Skip to content

Commit 734c210

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 9da0a85 commit 734c210

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

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

Lines changed: 29 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

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

0 commit comments

Comments
 (0)