From d847560d7c9909bc2c6cb1d28c8f2f20b96d9027 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 21 Mar 2020 10:54:02 +0100 Subject: [PATCH] Fix rubocop issues --- app/controllers/admin/enterprises_controller.rb | 3 ++- app/helpers/injection_helper.rb | 16 +++++++++++++--- app/helpers/spree/base_helper_decorator.rb | 10 +++++----- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 4fad65ce37..6f74043078 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -33,7 +33,8 @@ module Admin end def edit - @object = Enterprise.where(permalink: params[:id]).includes(users: [:ship_address, :bill_address]).first + @object = Enterprise.where(permalink: params[:id]). + includes(users: [:ship_address, :bill_address]).first super end diff --git a/app/helpers/injection_helper.rb b/app/helpers/injection_helper.rb index a10a4b1fee..bbc05c938f 100644 --- a/app/helpers/injection_helper.rb +++ b/app/helpers/injection_helper.rb @@ -3,10 +3,10 @@ require 'open_food_network/enterprise_injection_data' module InjectionHelper include SerializerHelper - def inject_enterprises(enterprises = Enterprise.activated.includes(address: [:state, :country]).all) + def inject_enterprises(enterprises = nil) inject_json_ams( "enterprises", - enterprises, + enterprises || default_enterprise_query, Api::EnterpriseSerializer, enterprise_injection_data ) @@ -41,8 +41,14 @@ module InjectionHelper end def inject_enterprise_and_relatives + enterprises_and_relatives = current_distributor. + relatives_including_self. + activated. + includes(address: [:state, :country]). + all + inject_json_ams "enterprises", - current_distributor.relatives_including_self.activated.includes(address: [:state, :country]).all, + enterprises_and_relatives, Api::EnterpriseSerializer, enterprise_injection_data end @@ -140,6 +146,10 @@ module InjectionHelper private + def default_enterprise_query + Enterprise.activated.includes(address: [:state, :country]).all + end + def enterprise_injection_data @enterprise_injection_data ||= OpenFoodNetwork::EnterpriseInjectionData.new { data: @enterprise_injection_data } diff --git a/app/helpers/spree/base_helper_decorator.rb b/app/helpers/spree/base_helper_decorator.rb index 8d80c51d9a..0125347d58 100644 --- a/app/helpers/spree/base_helper_decorator.rb +++ b/app/helpers/spree/base_helper_decorator.rb @@ -10,11 +10,11 @@ module Spree def available_countries checkout_zone = Zone.find_by_name(Spree::Config[:checkout_zone]) - if checkout_zone && checkout_zone.kind == 'country' - countries = checkout_zone.country_list - else - countries = Country.includes(:states).all - end + countries = if checkout_zone && checkout_zone.kind == 'country' + checkout_zone.country_list + else + Country.includes(:states).all + end countries.collect do |country| country.name = Spree.t(country.iso, scope: 'country_names', default: country.name)