From 437da7425c82c6d2d9cb7c260dc869d5753f7416 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 5 Jun 2013 14:55:56 +1000 Subject: [PATCH] Add spec for OrderPopulator#attempt_cart_add --- spec/models/order_populator_spec.rb | 35 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/spec/models/order_populator_spec.rb b/spec/models/order_populator_spec.rb index 935cd575ef..831e97866e 100644 --- a/spec/models/order_populator_spec.rb +++ b/spec/models/order_populator_spec.rb @@ -7,12 +7,11 @@ module Spree let(:params) { double(:params) } let(:distributor) { double(:distributor) } let(:order_cycle) { double(:order_cycle) } + let(:op) { OrderPopulator.new(order, currency) } describe "populate" do it "checks that distributor can supply all products in the cart" do - op = OrderPopulator.new(order, currency) - op.should_receive(:load_distributor_and_order_cycle).with(params). and_return([distributor, order_cycle]) op.should_receive(:distributor_can_supply_products_in_cart).with(distributor). @@ -25,8 +24,6 @@ module Spree end it "doesn't set cart distributor and order cycle if populate fails" do - op = OrderPopulator.new(order, currency) - op.should_receive(:load_distributor_and_order_cycle).with(params). and_return([distributor, order_cycle]) op.should_receive(:distributor_can_supply_products_in_cart).with(distributor). @@ -45,8 +42,6 @@ module Spree end it "sets cart distributor and order cycle when populate succeeds" do - op = OrderPopulator.new(order, currency) - op.should_receive(:load_distributor_and_order_cycle).with(params). and_return([distributor, order_cycle]) op.should_receive(:distributor_can_supply_products_in_cart).with(distributor). @@ -54,16 +49,38 @@ module Spree op.should_receive(:populate_without_distribution_validation).with(params) op.should_receive(:set_cart_distributor_and_order_cycle).with(distributor, order_cycle) - op.populate(params).should be_true + op.populate(params).should be_true end end describe "attempt_cart_add" do - it "validates distribution is provided" - it "validates variant is available under distributor" + it "performs additional validations" do + variant = double(:variant) + quantity = 123 + Spree::Variant.stub(:find).and_return(variant) + + op.should_receive(:check_stock_levels).with(variant, quantity).and_return(true) + op.should_receive(:check_distribution_provided_for).with(variant).and_return(true) + op.should_receive(:check_variant_available_under_distributor).with(variant). + and_return(true) + order.should_receive(:add_variant).with(variant, quantity, currency) + + op.attempt_cart_add(333, quantity.to_s) + end + end + + describe "support" do + it "loads distributor and order cycle from hash" + it "sets cart distributor and order cycle" end 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" + end + describe "checking distribution is provided for a variant" do end