From f4df69765d19019541b629bc38000f43c85350a8 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 5 Jun 2013 15:09:11 +1000 Subject: [PATCH] Add spec for OrderPopulator#distributor_can_supply_products_in_cart --- app/models/spree/order_populator_decorator.rb | 8 ++++---- spec/models/order_populator_spec.rb | 20 ++++++++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/models/spree/order_populator_decorator.rb b/app/models/spree/order_populator_decorator.rb index e8db020101..fa2278309c 100644 --- a/app/models/spree/order_populator_decorator.rb +++ b/app/models/spree/order_populator_decorator.rb @@ -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 = diff --git a/spec/models/order_populator_spec.rb b/spec/models/order_populator_spec.rb index 3380e6204e..8135f1069a 100644 --- a/spec/models/order_populator_spec.rb +++ b/spec/models/order_populator_spec.rb @@ -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