From f0d335a45437663b5e9c457bfef5be6804c9b286 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 7 Nov 2013 11:47:05 +1100 Subject: [PATCH] Fixing up the failing spec for distributor changes, reworking a method to SharedHelper --- app/helpers/temp_landing_page_helper.rb | 9 +++++++ db/schema.rb | 2 +- spec/helpers/shared_helper_spec.rb | 27 +++++++++++++++++++ spec/helpers/temp_landing_page_helper_spec.rb | 23 +--------------- spec/models/spree/order_spec.rb | 1 + 5 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 spec/helpers/shared_helper_spec.rb diff --git a/app/helpers/temp_landing_page_helper.rb b/app/helpers/temp_landing_page_helper.rb index fc4617f1b1..02277e7322 100644 --- a/app/helpers/temp_landing_page_helper.rb +++ b/app/helpers/temp_landing_page_helper.rb @@ -1,2 +1,11 @@ module TempLandingPageHelper + def temp_landing_page_distributor_link_class(distributor) + cart = current_order(true) + @active_distributors ||= Enterprise.distributors_with_active_order_cycles + + klass = "shop-distributor" + klass += " empties-cart" unless cart.line_items.empty? || cart.distributor == distributor + klass += @active_distributors.include?(distributor) ? ' active' : ' inactive' + klass + end end diff --git a/db/schema.rb b/db/schema.rb index d24254c517..a95c7c04b5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -481,9 +481,9 @@ ActiveRecord::Schema.define(:version => 20131030031125) do t.string "email" t.text "special_instructions" t.integer "distributor_id" + t.integer "order_cycle_id" t.string "currency" t.string "last_ip_address" - t.integer "order_cycle_id" t.integer "cart_id" end diff --git a/spec/helpers/shared_helper_spec.rb b/spec/helpers/shared_helper_spec.rb new file mode 100644 index 0000000000..65d978d86c --- /dev/null +++ b/spec/helpers/shared_helper_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe SharedHelper do + + it "does not require emptying the cart when it is empty" do + d = double(:distributor) + order = double(:order, line_items: []) + helper.stub(:current_order) { order } + helper.distributor_link_class(d).should_not =~ /empties-cart/ + end + + it "does not require emptying the cart when we are on the same distributor" do + d = double(:distributor) + order = double(:order, line_items: [double(:line_item)], distributor: d) + helper.stub(:current_order) { order } + helper.distributor_link_class(d).should_not =~ /empties-cart/ + end + + it "requires emptying the cart otherwise" do + d1 = double(:distributor) + d2 = double(:distributor) + order = double(:order, line_items: [double(:line_item)], distributor: d2) + helper.stub(:current_order) { order } + helper.distributor_link_class(d1).should =~ /empties-cart/ + end + +end diff --git a/spec/helpers/temp_landing_page_helper_spec.rb b/spec/helpers/temp_landing_page_helper_spec.rb index b82e600cef..625dca57f4 100644 --- a/spec/helpers/temp_landing_page_helper_spec.rb +++ b/spec/helpers/temp_landing_page_helper_spec.rb @@ -1,26 +1,5 @@ require 'spec_helper' -describe HtmlHelper do - it "does not require emptying the cart when it is empty" do - d = double(:distributor) - order = double(:order, line_items: []) - helper.stub(:current_order) { order } - helper.temp_landing_page_distributor_link_class(d).should_not =~ /empties-cart/ - end - - it "does not require emptying the cart when we are on the same distributor" do - d = double(:distributor) - order = double(:order, line_items: [double(:line_item)], distributor: d) - helper.stub(:current_order) { order } - helper.temp_landing_page_distributor_link_class(d).should_not =~ /empties-cart/ - end - - it "requires emptying the cart otherwise" do - d1 = double(:distributor) - d2 = double(:distributor) - order = double(:order, line_items: [double(:line_item)], distributor: d2) - helper.stub(:current_order) { order } - helper.temp_landing_page_distributor_link_class(d1).should =~ /empties-cart/ - end +describe TempLandingPageHelper do end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 343c032458..06f82dacac 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -191,6 +191,7 @@ describe Spree::Order do context "validating distributor changes" do it "checks that a distributor is available when changing" do + set_feature_toggle :order_cycles, false order_enterprise = FactoryGirl.create(:enterprise, id: 1, :name => "Order Enterprise") subject.distributor = order_enterprise product1 = FactoryGirl.create(:product)