Skip to content

Commit 9da0a85

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

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,5 +303,30 @@ def allocate_inventory(desired)
303303
expect(subject.shipments.flat_map(&:inventory_units).all?(&:backordered?)).to be true
304304
end
305305
end
306+
307+
describe "to customize the stock locator filter behavior" do
308+
let(:coordinator_options) { {force_specific_stock_location: specific_stock_location} }
309+
let(:specific_stock_location) { create(:stock_location) }
310+
311+
around do |example|
312+
MyLocatorFilter = Class.new(Spree::Stock::LocationFilter::Active) do
313+
def filter
314+
coordinator_options[:force_specific_stock_location] ?
315+
[coordinator_options[:force_specific_stock_location]]
316+
: super
317+
end
318+
end
319+
320+
original_locator_filter_class = Spree::Config.stock.location_filter_class
321+
Spree::Config.stock.location_filter_class = MyLocatorFilter.to_s
322+
example.run
323+
Spree::Config.stock.location_filter_class =
324+
original_locator_filter_class.to_s
325+
end
326+
327+
it "uses the options to force a specific stock location" do
328+
expect(subject.shipments.map(&:stock_location)).to eq [specific_stock_location]
329+
end
330+
end
306331
end
307332
end

0 commit comments

Comments
 (0)