From e48c921c77ef20ff5168a535fa5ee65769a4515b Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 21 Mar 2017 12:44:47 +0100 Subject: [PATCH] Fix complete order factory to have non-pending inventory units When an order is completed, all its inventory units are by default set to `pending: false`. The factory should reflect that. This made a change to the shipment spec necessary. That spec is setup with a completed order, and then runs `Spree::Shipment#finalize`, which is run at order completion, so I manually reset the inventory unit to pending. --- core/lib/spree/testing_support/factories/order_factory.rb | 4 +++- .../core/testing_support/factories/order_factory_spec.rb | 2 ++ core/spec/models/spree/shipment_spec.rb | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/lib/spree/testing_support/factories/order_factory.rb b/core/lib/spree/testing_support/factories/order_factory.rb index 7884426922f..0e0e5aaa736 100644 --- a/core/lib/spree/testing_support/factories/order_factory.rb +++ b/core/lib/spree/testing_support/factories/order_factory.rb @@ -76,6 +76,9 @@ after(:create) do |order| order.refresh_shipment_rates + order.shipments.each do |shipment| + shipment.inventory_units.update_all state: 'on_hand', pending: false + end order.update_column(:completed_at, Time.current) end @@ -96,7 +99,6 @@ after(:create) do |order, evaluator| create(evaluator.payment_type, amount: order.total, order: order, state: 'completed') order.shipments.each do |shipment| - shipment.inventory_units.update_all state: 'on_hand' shipment.update_column('state', 'ready') end order.reload diff --git a/core/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb b/core/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb index 44c511464ef..268005e9c97 100644 --- a/core/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +++ b/core/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb @@ -122,6 +122,8 @@ total: 110, state: 'complete' ) + expect(order.inventory_units.where(pending: true)).to be_empty + expect(order.inventory_units.where(pending: false)).to_not be_empty end end end diff --git a/core/spec/models/spree/shipment_spec.rb b/core/spec/models/spree/shipment_spec.rb index 06ea05db799..8860ba6bffd 100644 --- a/core/spec/models/spree/shipment_spec.rb +++ b/core/spec/models/spree/shipment_spec.rb @@ -753,6 +753,7 @@ before do stock_item.set_count_on_hand(10) stock_item.update_attributes!(backorderable: false) + inventory_unit.update_attributes!(pending: true) end subject { shipment.finalize! }