Skip to content

Commit 860927d

Browse files
Test custom Stock Location Sorter coordinator options integration
This commit ensures that the simple coordinator and a custom stock location sort work when custom coordinator options are passed in. Co-authored-by: Benjamin Willems <benjamin@super.gd>
1 parent f802f74 commit 860927d

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

core/spec/models/spree/stock/simple_coordinator_integration_spec.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
end
236236

237237
context "when custom coordinator options are passed" do
238-
let(:order) {
238+
let!(:order) {
239239
create :order_with_line_items, line_items_attributes: [{variant: create(:product_in_stock).master }]
240240
}
241241

@@ -326,5 +326,32 @@ def filter
326326
expect(subject.shipments.map(&:stock_location)).to eq [specific_stock_location]
327327
end
328328
end
329+
330+
describe "to customize the stock location sorters behavior" do
331+
let(:coordinator_options) { {force_stock_location_order: [stock_location_2, stock_location_1]} }
332+
let!(:stock_location_1) { create(:stock_location, active: true, propagate_all_variants: true) }
333+
let!(:stock_location_2) { create(:stock_location, active: true, propagate_all_variants: true) }
334+
335+
before do
336+
Spree::StockItem.update_all(count_on_hand: 999)
337+
end
338+
339+
around do |example|
340+
MyLocationSorter = Class.new(Spree::Stock::LocationSorter::DefaultFirst) do
341+
def sort
342+
coordinator_options[:force_stock_location_order] || super
343+
end
344+
end
345+
346+
original_location_sorter_class = Spree::Config.stock.location_sorter_class
347+
Spree::Config.stock.location_sorter_class = MyLocationSorter.to_s
348+
example.run
349+
Spree::Config.stock.location_sorter_class = original_location_sorter_class
350+
end
351+
352+
it "uses the options to force a specific stock location order" do
353+
expect(subject.shipments.map(&:stock_location)).to all(eq(stock_location_2))
354+
end
355+
end
329356
end
330357
end

0 commit comments

Comments
 (0)