Skip to content

Commit

Permalink
Fix complete order factory to have non-pending inventory units
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mamhoff committed Mar 21, 2017
1 parent 454ab43 commit e48c921
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/lib/spree/testing_support/factories/order_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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! }
Expand Down

0 comments on commit e48c921

Please sign in to comment.