From ddf916814f02617310a4bac9fd9df5f720e1ebe4 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 3 Jan 2019 11:14:51 +0100 Subject: [PATCH] Reduce complexity of EnterprisesController#shop As asked by Rubocop. --- app/controllers/enterprises_controller.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 35100ff6b9..cfaab8de47 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -17,17 +17,12 @@ class EnterprisesController < BaseController return redirect_to spree.cart_path unless enough_stock? set_noindex_meta_tag - order_cycles = if current_order_cycle - [current_order_cycle] - else - OrderCycle.not_closed.with_distributor(current_distributor) - end - enterprises = current_distributor - .plus_relatives_and_oc_producers(order_cycles) + .plus_relatives_and_oc_producers(shop_order_cycles) .activated .includes(address: :state) .all + enterprises = inject_json_ams('enterprises', enterprises) render locals: { enterprises: enterprises } @@ -102,6 +97,14 @@ class EnterprisesController < BaseController order.order_cycle = order_cycle_options.first if order_cycle_options.count == 1 end + def shop_order_cycles + if current_order_cycle + [current_order_cycle] + else + OrderCycle.not_closed.with_distributor(current_distributor) + end + end + def set_noindex_meta_tag @noindex_meta_tag = true unless current_distributor.visible? end