Add factory for orders

This commit is contained in:
Tim Kächele 2023-10-28 14:06:03 +02:00
parent d168a36fda
commit b3b31427db
3 changed files with 17 additions and 9 deletions

View File

@ -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
View 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

View File

@ -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