Add factory for orders
This commit is contained in:
parent
d168a36fda
commit
b3b31427db
@ -1,16 +1,14 @@
|
||||
module Rex
|
||||
class Order
|
||||
attr_accessor(
|
||||
:next_order,
|
||||
:remaining_amount
|
||||
)
|
||||
|
||||
attr_reader(
|
||||
:id,
|
||||
:is_buy,
|
||||
:price,
|
||||
:user_id,
|
||||
:amount
|
||||
:amount,
|
||||
:previous_order,
|
||||
:next_order,
|
||||
:remaining_amount
|
||||
)
|
||||
|
||||
def initialize(attrs = {})
|
||||
@ -23,6 +21,7 @@ module Rex
|
||||
@remaining_amount = attrs[:amount]
|
||||
|
||||
@next_order = nil
|
||||
@previous_order = nil
|
||||
end
|
||||
|
||||
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
|
||||
describe "#filled?" do
|
||||
let(:order) do
|
||||
instance = described_class.new(
|
||||
amount: 100
|
||||
)
|
||||
instance = build(:order)
|
||||
instance.remaining_amount = remaining_amount
|
||||
instance
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user