mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-17 00:07:24 +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
|
||||
|
||||
@@ -21,7 +21,7 @@ module Spree
|
||||
op.populate(params).should be_false
|
||||
op.errors.to_a.should == ["That distributor or order cycle can't supply all the products in your cart. Please choose another."]
|
||||
end
|
||||
|
||||
|
||||
it "empties the order if override is true" do
|
||||
op.stub(:distribution_can_supply_products_in_cart).and_return true
|
||||
order.stub(:with_lock).and_yield
|
||||
@@ -38,7 +38,7 @@ module Spree
|
||||
it "attempts cart add with max_quantity" do
|
||||
op.stub(:distribution_can_supply_products_in_cart).and_return true
|
||||
order.should_receive(:empty!)
|
||||
params = {variants: {"1" => {quantity: 1, max_quantity: 2}}}
|
||||
params = {variants: {"1" => {quantity: 1, max_quantity: 2}}}
|
||||
order.stub(:with_lock).and_yield
|
||||
op.should_receive(:attempt_cart_add).with("1", 1, 2).and_return true
|
||||
op.populate(params, true)
|
||||
@@ -48,7 +48,6 @@ module Spree
|
||||
describe "attempt_cart_add" do
|
||||
it "performs additional validations" do
|
||||
variant = double(:variant)
|
||||
variant.stub(:scope_to_hub)
|
||||
quantity = 123
|
||||
Spree::Variant.stub(:find).and_return(variant)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user