mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Fixing up the failing spec for distributor changes, reworking a method to SharedHelper
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
27
spec/helpers/shared_helper_spec.rb
Normal file
27
spec/helpers/shared_helper_spec.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user