Skip to content

Commit fa4635f

Browse files
committed
Extract shared example for later reuse
These specs don't really require a specific first level scenario, so we're first extracting them to a shared example, and with the following commit we're going to use it in other existing scenarios.
1 parent 89d1174 commit fa4635f

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

core/spec/models/spree/fulfilment_changer_spec.rb

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,45 +81,47 @@
8181
end
8282
end
8383

84-
subject { shipment_splitter.run! }
85-
86-
before do
87-
variant.stock_items.first.update_column(:count_on_hand, 100)
88-
end
89-
90-
context "when the current shipment stock location is the same of the target shipment" do
91-
let(:current_shipment_inventory_unit_count) { 1 }
92-
let(:quantity) { current_shipment_inventory_unit_count }
93-
84+
shared_examples_for "properly manages inventory units" do
9485
context "when the stock location is empty" do
95-
before do
96-
variant.stock_items.first.update_column(:count_on_hand, 0)
97-
end
86+
let(:stock_item) { variant.stock_items.find_by!(stock_location: current_shipment.stock_location) }
87+
88+
before { stock_item.update_column(:count_on_hand, 0) }
9889

99-
context "when the inventory unit is backordered" do
90+
context "when there are backordered inventory units" do
10091
before do
101-
current_shipment.inventory_units.first.update state: :backordered
92+
current_shipment.inventory_units.first.update(state: :backordered)
10293
end
10394

104-
it "creates a new backordered inventory unit" do
105-
subject
106-
expect(desired_shipment.inventory_units.first).to be_backordered
95+
it "doesn't change the order inventory units state" do
96+
expect { subject }.not_to change { order.inventory_units.map(&:state).sort }
10797
end
10898
end
10999

110-
context "when the inventory unit is on hand" do
100+
context "when all inventory units are on hand" do
111101
before do
112-
current_shipment.inventory_units.first.update state: :on_hand
102+
current_shipment.inventory_units.update_all(state: :on_hand)
113103
end
114104

115-
it "creates a new on hand inventory unit" do
116-
subject
117-
expect(desired_shipment.inventory_units.first).to be_on_hand
105+
it "doesn't change the order inventory units state" do
106+
expect { subject }.not_to change { order.inventory_units.map(&:state).sort }
118107
end
119108
end
120109
end
121110
end
122111

112+
subject { shipment_splitter.run! }
113+
114+
before do
115+
variant.stock_items.first.update_column(:count_on_hand, 100)
116+
end
117+
118+
context "when the current shipment stock location is the same of the target shipment" do
119+
let(:current_shipment_inventory_unit_count) { 1 }
120+
let(:quantity) { current_shipment_inventory_unit_count }
121+
122+
it_behaves_like "properly manages inventory units"
123+
end
124+
123125
context "when tracking inventory is not set (same as false)" do
124126
let(:current_shipment_inventory_unit_count) { 2 }
125127
let(:quantity) { 1 }

0 commit comments

Comments
 (0)