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:
Rohan Mitchell
2015-06-18 13:11:11 +10:00
parent 6ed9a2620c
commit 7cc2bc4fde
11 changed files with 67 additions and 57 deletions

View File

@@ -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