From b3b31427db581805d8bfd01db0afbe610389227e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20K=C3=A4chele?= Date: Sat, 28 Oct 2023 14:06:03 +0200 Subject: [PATCH] Add factory for orders --- lib/rex/order.rb | 11 +++++------ spec/factories/orders.rb | 11 +++++++++++ spec/order_spec.rb | 4 +--- 3 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 spec/factories/orders.rb diff --git a/lib/rex/order.rb b/lib/rex/order.rb index 8d6882e..c3ba5af 100644 --- a/lib/rex/order.rb +++ b/lib/rex/order.rb @@ -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? diff --git a/spec/factories/orders.rb b/spec/factories/orders.rb new file mode 100644 index 0000000..f61c2a0 --- /dev/null +++ b/spec/factories/orders.rb @@ -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 diff --git a/spec/order_spec.rb b/spec/order_spec.rb index cdb1aa2..19bd06a 100644 --- a/spec/order_spec.rb +++ b/spec/order_spec.rb @@ -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