mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-14 04:04:23 +00:00
Perform variant override scoping on product/variant by external class. Centralise this so we can load everything in one go.
This commit is contained in:
@@ -5,16 +5,17 @@ module OpenFoodNetwork
|
||||
let(:hub) { create(:distributor_enterprise) }
|
||||
let(:v) { create(:variant, price: 11.11, count_on_hand: 1) }
|
||||
let(:vo) { create(:variant_override, hub: hub, variant: v, price: 22.22, count_on_hand: 2) }
|
||||
let(:scoper) { ScopeVariantToHub.new(hub) }
|
||||
|
||||
describe "overriding price" do
|
||||
it "returns the overridden price when one is present" do
|
||||
vo
|
||||
v.scope_to_hub hub
|
||||
scoper.scope v
|
||||
v.price.should == 22.22
|
||||
end
|
||||
|
||||
it "returns the variant's price otherwise" do
|
||||
v.scope_to_hub hub
|
||||
scoper.scope v
|
||||
v.price.should == 11.11
|
||||
end
|
||||
end
|
||||
@@ -22,12 +23,12 @@ module OpenFoodNetwork
|
||||
describe "overriding price_in" do
|
||||
it "returns the overridden price when one is present" do
|
||||
vo
|
||||
v.scope_to_hub hub
|
||||
scoper.scope v
|
||||
v.price_in('AUD').amount.should == 22.22
|
||||
end
|
||||
|
||||
it "returns the variant's price otherwise" do
|
||||
v.scope_to_hub hub
|
||||
scoper.scope v
|
||||
v.price_in('AUD').amount.should == 11.11
|
||||
end
|
||||
end
|
||||
@@ -35,12 +36,12 @@ module OpenFoodNetwork
|
||||
describe "overriding stock levels" do
|
||||
it "returns the overridden stock level when one is present" do
|
||||
vo
|
||||
v.scope_to_hub hub
|
||||
scoper.scope v
|
||||
v.count_on_hand.should == 2
|
||||
end
|
||||
|
||||
it "returns the variant's stock level otherwise" do
|
||||
v.scope_to_hub hub
|
||||
scoper.scope v
|
||||
v.count_on_hand.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user