Add factory for orders
This commit is contained in:
parent
d168a36fda
commit
b3b31427db
@ -1,16 +1,14 @@
|
|||||||
module Rex
|
module Rex
|
||||||
class Order
|
class Order
|
||||||
attr_accessor(
|
attr_accessor(
|
||||||
:next_order,
|
|
||||||
:remaining_amount
|
|
||||||
)
|
|
||||||
|
|
||||||
attr_reader(
|
|
||||||
:id,
|
:id,
|
||||||
:is_buy,
|
:is_buy,
|
||||||
:price,
|
:price,
|
||||||
:user_id,
|
:user_id,
|
||||||
:amount
|
:amount,
|
||||||
|
:previous_order,
|
||||||
|
:next_order,
|
||||||
|
:remaining_amount
|
||||||
)
|
)
|
||||||
|
|
||||||
def initialize(attrs = {})
|
def initialize(attrs = {})
|
||||||
@ -23,6 +21,7 @@ module Rex
|
|||||||
@remaining_amount = attrs[:amount]
|
@remaining_amount = attrs[:amount]
|
||||||
|
|
||||||
@next_order = nil
|
@next_order = nil
|
||||||
|
@previous_order = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def filled?
|
def filled?
|
||||||
|
11
spec/factories/orders.rb
Normal file
11
spec/factories/orders.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :order, class: Rex::Order do
|
||||||
|
sequence(:id) { |i| i }
|
||||||
|
sequence(:user_id) { |i| i }
|
||||||
|
sequence(:is_buy) { |i| (i % 2).zero? }
|
||||||
|
sequence(:price) { 100 }
|
||||||
|
sequence(:amount) { 20 }
|
||||||
|
end
|
||||||
|
end
|
@ -3,9 +3,7 @@
|
|||||||
RSpec.describe Rex::Order do
|
RSpec.describe Rex::Order do
|
||||||
describe "#filled?" do
|
describe "#filled?" do
|
||||||
let(:order) do
|
let(:order) do
|
||||||
instance = described_class.new(
|
instance = build(:order)
|
||||||
amount: 100
|
|
||||||
)
|
|
||||||
instance.remaining_amount = remaining_amount
|
instance.remaining_amount = remaining_amount
|
||||||
instance
|
instance
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user