mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-17 04:34:24 +00:00
Skip methods that distributor can't use in Package
This ensures that Spree's shipping methods take into account the ones the order's distributor uses. This reimplements what `#available_to_order_with_distributor_check?` used to do and it doesn't work with Spree 2.0.4.
This commit is contained in:
51
spec/models/stock/package_spec.rb
Normal file
51
spec/models/stock/package_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Stock
|
||||
describe Package do
|
||||
describe '#shipping_methods' do
|
||||
let(:stock_location) { double(:stock_location) }
|
||||
let(:order) { build(:order) }
|
||||
|
||||
subject(:package) { Package.new(stock_location, order, contents) }
|
||||
|
||||
describe '#shipping_methods' do
|
||||
let(:enterprise) { build(:enterprise) }
|
||||
let(:other_enterprise) { build(:enterprise) }
|
||||
|
||||
let(:order) { build(:order, distributor: enterprise) }
|
||||
|
||||
let(:variant1) do
|
||||
instance_double(
|
||||
Spree::Variant,
|
||||
shipping_category: shipping_method1.shipping_categories.first
|
||||
)
|
||||
end
|
||||
let(:variant2) do
|
||||
instance_double(
|
||||
Spree::Variant,
|
||||
shipping_category: shipping_method2.shipping_categories.first
|
||||
)
|
||||
end
|
||||
let(:variant3) do
|
||||
instance_double(Spree::Variant, shipping_category: nil)
|
||||
end
|
||||
|
||||
let(:contents) do
|
||||
[
|
||||
Package::ContentItem.new(variant1, 1),
|
||||
Package::ContentItem.new(variant1, 1),
|
||||
Package::ContentItem.new(variant2, 1),
|
||||
Package::ContentItem.new(variant3, 1)
|
||||
]
|
||||
end
|
||||
|
||||
let(:shipping_method1) { create(:shipping_method, distributors: [enterprise]) }
|
||||
let(:shipping_method2) { create(:shipping_method, distributors: [other_enterprise]) }
|
||||
|
||||
it 'does not return shipping methods not used by the package\'s order distributor' do
|
||||
expect(package.shipping_methods).to eq [shipping_method1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user