From 26cb6a62f603db6fa4b63d0d7c895effa639c08a Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 12 Apr 2017 15:00:21 +1000 Subject: [PATCH 1/2] Remove useless `andand` called on scope --- lib/open_food_network/enterprise_injection_data.rb | 2 +- spec/controllers/shops_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/open_food_network/enterprise_injection_data.rb b/lib/open_food_network/enterprise_injection_data.rb index 2c8b470069d..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.andand.ready_for_checkout + @active_distributors ||= Enterprise.distributors_with_active_order_cycles.ready_for_checkout end def earliest_closing_times diff --git a/spec/controllers/shops_controller_spec.rb b/spec/controllers/shops_controller_spec.rb index 2e11011c57c..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_chain("distributors_with_active_order_cycles.andand.ready_for_checkout") { [distributor] } + Enterprise.stub_chain("distributors_with_active_order_cycles.ready_for_checkout") { [distributor] } end # Exclusion from actual rendered view handled in features/consumer/home From 46ea091f62b1053f37cf494410a7d03632724cfa Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 12 Apr 2017 15:17:42 +1000 Subject: [PATCH 2/2] Fast fail `set_order_cycles` if distributor not ready --- app/controllers/base_controller.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index e5535b71ad1..7f9a0f2df61 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -23,11 +23,14 @@ 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) - ensure_shop_ready - applicator = OpenFoodNetwork::TagRuleApplicator.new(@distributor, "FilterOrderCycles", current_customer.andand.tag_list) applicator.filter!(@order_cycles) @@ -36,9 +39,4 @@ def set_order_cycles current_order(true).set_order_cycle! @order_cycles.first end end - - def ensure_shop_ready - # Don't display order cycles if shop is not ready for checkout - @order_cycles = {} unless @distributor.ready_for_checkout? - end end