|
81 | 81 | end |
82 | 82 | end |
83 | 83 |
|
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 |
94 | 85 | 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) } |
98 | 89 |
|
99 | | - context "when the inventory unit is backordered" do |
| 90 | + context "when there are backordered inventory units" do |
100 | 91 | before do |
101 | | - current_shipment.inventory_units.first.update state: :backordered |
| 92 | + current_shipment.inventory_units.first.update(state: :backordered) |
102 | 93 | end |
103 | 94 |
|
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 } |
107 | 97 | end |
108 | 98 | end |
109 | 99 |
|
110 | | - context "when the inventory unit is on hand" do |
| 100 | + context "when all inventory units are on hand" do |
111 | 101 | before do |
112 | | - current_shipment.inventory_units.first.update state: :on_hand |
| 102 | + current_shipment.inventory_units.update_all(state: :on_hand) |
113 | 103 | end |
114 | 104 |
|
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 } |
118 | 107 | end |
119 | 108 | end |
120 | 109 | end |
121 | 110 | end |
122 | 111 |
|
| 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 | + |
123 | 125 | context "when tracking inventory is not set (same as false)" do |
124 | 126 | let(:current_shipment_inventory_unit_count) { 2 } |
125 | 127 | let(:quantity) { 1 } |
|
0 commit comments