From b924b0c817ed77bae63d35efdb0890a586ac80a0 Mon Sep 17 00:00:00 2001 From: Rob H Date: Thu, 14 Feb 2013 12:24:01 +1100 Subject: [PATCH] Remove unnecessary include of Spree::Core::CurrentOrder (helper is now accessible by all controllers in Spree 1.3) --- .../enterprises_controller_spec.rb | 3 -- spec/controllers/orders_controller_spec.rb | 29 +++++++++---------- spec/support/spree/init.rb | 9 ++++++ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index a5709d3a74..6e45d4a58f 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -1,9 +1,6 @@ require 'spec_helper' -require 'spree/core/current_order' describe EnterprisesController do - include Spree::Core::CurrentOrder - before :each do stub!(:before_save_new_order) stub!(:after_save_new_order) diff --git a/spec/controllers/orders_controller_spec.rb b/spec/controllers/orders_controller_spec.rb index 440bf8fcbf..b8b2f51cad 100644 --- a/spec/controllers/orders_controller_spec.rb +++ b/spec/controllers/orders_controller_spec.rb @@ -1,9 +1,6 @@ require 'spec_helper' -require 'spree/core/current_order' describe Spree::OrdersController do - include Spree::Core::CurrentOrder - def current_user controller.current_user end @@ -15,7 +12,7 @@ describe Spree::OrdersController do spree_get :select_distributor, :id => d.id response.should be_redirect - order = current_order(false) + order = subject.current_order(false) order.distributor.should == d end @@ -23,7 +20,7 @@ describe Spree::OrdersController do d = create(:distributor_enterprise) p = create(:product, :distributors => [d]) - order = current_order(true) + order = subject.current_order(true) order.distributor = d order.save! @@ -59,7 +56,7 @@ describe Spree::OrdersController do distributor_no_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product]) - order = current_order(true) + order = subject.current_order(true) order.distributor = distributor_no_product order.save! @@ -79,7 +76,7 @@ describe Spree::OrdersController do spree_post :populate, :variants => {p.master.id => 1}, :distributor_id => d.id # Then our order should have its distributor set to the chosen distributor - current_order(false).distributor.should == d + subject.current_order(false).distributor.should == d end end @@ -91,8 +88,8 @@ describe Spree::OrdersController do # And the product is in the cart spree_post :populate, :variants => {@product.master.id => 1}, :distributor_id => @distributor.id - current_order(false).line_items.reload.map { |li| li.product }.should == [@product] - current_order(false).distributor.reload.should == @distributor + subject.current_order(false).line_items.reload.map { |li| li.product }.should == [@product] + subject.current_order(false).distributor.reload.should == @distributor end it "does not add the product if the product is not available at the order's distributor" do @@ -104,8 +101,8 @@ describe Spree::OrdersController do spree_post :populate, :variants => {p2.master.id => 1}, :distributor_id => d2.id # Then the product should not be added to the cart - current_order(false).line_items.reload.map { |li| li.product }.should == [@product] - current_order(false).distributor.reload.should == @distributor + subject.current_order(false).line_items.reload.map { |li| li.product }.should == [@product] + subject.current_order(false).distributor.reload.should == @distributor end it "does not add the product if the product is not available at the given distributor" do @@ -117,8 +114,8 @@ describe Spree::OrdersController do spree_post :populate, :variants => {p2.master.id => 1}, :distributor_id => @distributor.id # Then the product should not be added to the cart - current_order(false).line_items.reload.map { |li| li.product }.should == [@product] - current_order(false).distributor.reload.should == @distributor + subject.current_order(false).line_items.reload.map { |li| li.product }.should == [@product] + subject.current_order(false).distributor.reload.should == @distributor end it "does not add the product if the chosen distributor is different from the order's distributor" do @@ -130,8 +127,8 @@ describe Spree::OrdersController do spree_post :populate, :variants => {p2.master.id => 1}, :distributor_id => d2 # Then the product should not be added to the cart - current_order(false).line_items.reload.map { |li| li.product }.should == [@product] - current_order(false).distributor.reload.should == @distributor + subject.current_order(false).line_items.reload.map { |li| li.product }.should == [@product] + subject.current_order(false).distributor.reload.should == @distributor end end @@ -140,7 +137,7 @@ describe Spree::OrdersController do distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) - order = current_order(true) + order = subject.current_order(true) order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) diff --git a/spec/support/spree/init.rb b/spec/support/spree/init.rb index 0614e5085b..e667b402c9 100644 --- a/spec/support/spree/init.rb +++ b/spec/support/spree/init.rb @@ -8,3 +8,12 @@ ProductDistribution.class_eval do self.shipping_method ||= Spree::ShippingMethod.first || FactoryGirl.create(:shipping_method) end end + +# Create a default shipping method, required when creating orders +Spree::Order.class_eval do + before_create :init_shipping_method + + def init_shipping_method + FactoryGirl.create(:itemwise_shipping_method) if Spree::ShippingMethod.where("display_on != 'back_end'").empty? + end +end \ No newline at end of file