diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 36084c0225b..7f9a0f2df61 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -23,6 +23,11 @@ class BaseController < ApplicationController private def set_order_cycles + unless @distributor.ready_for_checkout? + @order_cycles = OrderCycle.where('false') + return + end + @order_cycles = OrderCycle.with_distributor(@distributor).active .order(@distributor.preferred_shopfront_order_cycle_order) diff --git a/lib/open_food_network/enterprise_injection_data.rb b/lib/open_food_network/enterprise_injection_data.rb index 938c8b3aab1..3d15344472d 100644 --- a/lib/open_food_network/enterprise_injection_data.rb +++ b/lib/open_food_network/enterprise_injection_data.rb @@ -1,7 +1,7 @@ module OpenFoodNetwork class EnterpriseInjectionData def active_distributors - @active_distributors ||= Enterprise.distributors_with_active_order_cycles + @active_distributors ||= Enterprise.distributors_with_active_order_cycles.ready_for_checkout end def earliest_closing_times diff --git a/spec/controllers/shop_controller_spec.rb b/spec/controllers/shop_controller_spec.rb index c3784df428d..eac8a399d22 100644 --- a/spec/controllers/shop_controller_spec.rb +++ b/spec/controllers/shop_controller_spec.rb @@ -1,7 +1,9 @@ require 'spec_helper' describe ShopController do - let(:distributor) { create(:distributor_enterprise) } + let!(:pm) { create(:payment_method) } + let!(:sm) { create(:shipping_method) } + let(:distributor) { create(:distributor_enterprise, payment_methods: [pm], shipping_methods: [sm]) } it "redirects to the home page if no distributor is selected" do spree_get :show diff --git a/spec/controllers/shops_controller_spec.rb b/spec/controllers/shops_controller_spec.rb index a4c66ea3a7f..2b99c5f62ca 100644 --- a/spec/controllers/shops_controller_spec.rb +++ b/spec/controllers/shops_controller_spec.rb @@ -6,7 +6,7 @@ let!(:invisible_distributor) { create(:distributor_enterprise, visible: false) } before do - Enterprise.stub(:distributors_with_active_order_cycles) { [distributor] } + Enterprise.stub_chain("distributors_with_active_order_cycles.ready_for_checkout") { [distributor] } end # Exclusion from actual rendered view handled in features/consumer/home diff --git a/spec/features/consumer/shops_spec.rb b/spec/features/consumer/shops_spec.rb index c9e8063e721..082bf57d792 100644 --- a/spec/features/consumer/shops_spec.rb +++ b/spec/features/consumer/shops_spec.rb @@ -6,8 +6,8 @@ let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } let!(:invisible_distributor) { create(:distributor_enterprise, visible: false) } - let(:d1) { create(:distributor_enterprise) } - let(:d2) { create(:distributor_enterprise) } + let!(:d1) { create(:distributor_enterprise, with_payment_and_shipping: true) } + let!(:d2) { create(:distributor_enterprise, with_payment_and_shipping: true) } let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) } let!(:producer) { create(:supplier_enterprise) } let!(:er) { create(:enterprise_relationship, parent: distributor, child: producer) } @@ -57,6 +57,20 @@ end end + describe "showing available hubs" do + let!(:hub) { create(:distributor_enterprise, with_payment_and_shipping: false) } + let!(:order_cycle) { create(:simple_order_cycle, distributors: [hub], coordinator: hub) } + let!(:producer) { create(:supplier_enterprise) } + let!(:er) { create(:enterprise_relationship, parent: hub, child: producer) } + + it "does not show hubs that are not ready for checkout" do + visit shops_path + + Enterprise.ready_for_checkout.should_not include hub + page.should_not have_content hub.name + end + end + describe "filtering by product property" do let!(:order_cycle) { create(:simple_order_cycle, distributors: [d1, d2], coordinator: create(:distributor_enterprise)) } let!(:p1) { create(:simple_product, supplier: producer) } @@ -92,7 +106,7 @@ describe "taxon badges" do let!(:closed_oc) { create(:closed_order_cycle, distributors: [shop], variants: [p_closed.variants.first]) } let!(:p_closed) { create(:simple_product, taxons: [taxon_closed]) } - let(:shop) { create(:distributor_enterprise) } + let(:shop) { create(:distributor_enterprise, with_payment_and_shipping: true) } let(:taxon_closed) { create(:taxon, name: 'Closed') } describe "open shops" do