Fixing up the failing spec for distributor changes, reworking a method to SharedHelper

This commit is contained in:
Will Marshall
2013-11-07 11:47:05 +11:00
parent e33ff15151
commit f0d335a454
5 changed files with 39 additions and 23 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)