mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add spec for OrderPopulator#distributor_can_supply_products_in_cart
This commit is contained in:
@@ -44,10 +44,6 @@ Spree::OrderPopulator.class_eval do
|
||||
[distributor, order_cycle]
|
||||
end
|
||||
|
||||
def distributor_can_supply_products_in_cart(distributor)
|
||||
!distributor || DistributionChangeValidator.new(@order).can_change_to_distributor?(distributor)
|
||||
end
|
||||
|
||||
def set_cart_distributor_and_order_cycle(distributor, order_cycle)
|
||||
# Using @order.reload or not performing any reload causes totals fields (ie. item_total)
|
||||
# to be set to zero
|
||||
@@ -57,6 +53,10 @@ Spree::OrderPopulator.class_eval do
|
||||
@order.set_order_cycle! order_cycle if order_cycle
|
||||
end
|
||||
|
||||
def distributor_can_supply_products_in_cart(distributor)
|
||||
!distributor || DistributionChangeValidator.new(@order).can_change_to_distributor?(distributor)
|
||||
end
|
||||
|
||||
def check_distribution_provided_for(variant)
|
||||
order_cycle_required = order_cycle_required_for(variant)
|
||||
distribution_provided =
|
||||
|
||||
@@ -101,9 +101,23 @@ module Spree
|
||||
|
||||
describe "validations" do
|
||||
describe "determining if distributor can supply products in cart" do
|
||||
it "returns true if no distributor is supplied"
|
||||
it "returns true if the order can be changed to that distributor"
|
||||
it "returns false otherwise"
|
||||
it "returns true if no distributor is supplied" do
|
||||
op.send(:distributor_can_supply_products_in_cart, nil).should be_true
|
||||
end
|
||||
|
||||
it "returns true if the order can be changed to that distributor" do
|
||||
dcv = double(:dcv)
|
||||
dcv.should_receive(:can_change_to_distributor?).with(distributor).and_return(true)
|
||||
DistributionChangeValidator.should_receive(:new).with(order).and_return(dcv)
|
||||
op.send(:distributor_can_supply_products_in_cart, distributor).should be_true
|
||||
end
|
||||
|
||||
it "returns false otherwise" do
|
||||
dcv = double(:dcv)
|
||||
dcv.should_receive(:can_change_to_distributor?).with(distributor).and_return(false)
|
||||
DistributionChangeValidator.should_receive(:new).with(order).and_return(dcv)
|
||||
op.send(:distributor_can_supply_products_in_cart, distributor).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "checking distribution is provided for a variant" do
|
||||
|
||||
Reference in New Issue
Block a user