From cca15e75a6ccc79d207443ee709305871746eea8 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 28 Dec 2018 20:40:32 +0100 Subject: [PATCH 1/6] Refactor to reveal how we load enterprises in shop By sticking to Rails conventions we make it more obvious how (badly) we are loading enterprises in EnterprisesController#shop and shed some light on the obscure InjectionHelper. This will also make it easier to improve its performance in the future as it's among the top offenders. See https://www.skylight.io/app/applications/ibo3NOqCYMnq/1545851520/1d/endpoints/EnterprisesController%23shop?responseType=html --- app/controllers/enterprises_controller.rb | 27 ++++++++++++++++++++++- app/helpers/injection_helper.rb | 9 -------- app/views/enterprises/shop.html.haml | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 00af18d701..6a817a47d7 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -7,13 +7,28 @@ class EnterprisesController < BaseController # These prepended filters are in the reverse order of execution prepend_before_filter :set_order_cycles, :require_distributor_chosen, :reset_order, only: :shop - before_filter :check_stock_levels, :set_noindex_meta_tag, only: :shop before_filter :clean_permalink, only: :check_permalink before_filter :enable_embedded_shopfront respond_to :js, only: :permalink_checker + def shop + check_stock_levels + 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).activated.includes(address: :state).all + enterprises = inject_json_ams('enterprises', enterprises) + + render locals: { enterprises: enterprises } + end + def relatives set_enterprise @@ -88,4 +103,14 @@ class EnterprisesController < BaseController def set_noindex_meta_tag @noindex_meta_tag = true unless current_distributor.visible? end + + def inject_json_ams(name, object) + options = { + each_serializer: Api::EnterpriseSerializer, + data: OpenFoodNetwork::EnterpriseInjectionData.new + } + serializer_instance = ActiveModel::ArraySerializer.new(object, options) + + { name: name, json: serializer_instance.to_json } + end end diff --git a/app/helpers/injection_helper.rb b/app/helpers/injection_helper.rb index dfcf2bb6ff..52d178cb74 100644 --- a/app/helpers/injection_helper.rb +++ b/app/helpers/injection_helper.rb @@ -14,15 +14,6 @@ module InjectionHelper inject_json_ams "enterprises", current_distributor.relatives_including_self.activated.includes(address: :state).all, Api::EnterpriseSerializer, enterprise_injection_data end - def inject_shop_enterprises - ocs = if current_order_cycle - [current_order_cycle] - else - OrderCycle.not_closed.with_distributor(current_distributor) - end - inject_json_ams "enterprises", current_distributor.plus_relatives_and_oc_producers(ocs).activated.includes(address: :state).all, Api::EnterpriseSerializer, enterprise_injection_data - end - def inject_group_enterprises inject_json_ams "group_enterprises", @group.enterprises.activated.all, Api::EnterpriseSerializer, enterprise_injection_data end diff --git a/app/views/enterprises/shop.html.haml b/app/views/enterprises/shop.html.haml index f05ac115f3..041c8be07b 100644 --- a/app/views/enterprises/shop.html.haml +++ b/app/views/enterprises/shop.html.haml @@ -5,7 +5,7 @@ - content_for(:image) do = current_distributor.logo.url -= inject_shop_enterprises += render partial: 'json/injection_ams', locals: enterprises %shop.darkswarm - if @shopfront_layout == 'embedded' From 46760ce28c98ec4a9da1b724713f4968691ae54a Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Sun, 30 Dec 2018 11:42:37 +0100 Subject: [PATCH 2/6] Do not double-render when there is no stock --- app/controllers/enterprises_controller.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 6a817a47d7..83f8ae93cf 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -14,7 +14,7 @@ class EnterprisesController < BaseController respond_to :js, only: :permalink_checker def shop - check_stock_levels + return redirect_to spree.cart_path unless enough_stock? set_noindex_meta_tag order_cycles = if current_order_cycle @@ -63,10 +63,8 @@ class EnterprisesController < BaseController params[:permalink] = params[:permalink].parameterize end - def check_stock_levels - if current_order(true).insufficient_stock_lines.present? - redirect_to spree.cart_path - end + def enough_stock? + current_order(true).insufficient_stock_lines.blank? end def reset_order From 51da607ab1868ed64815194a660703b7728a2de2 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 2 Jan 2019 13:07:52 +0100 Subject: [PATCH 3/6] Fix too long line --- app/controllers/enterprises_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 83f8ae93cf..35100ff6b9 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -23,7 +23,11 @@ class EnterprisesController < BaseController OrderCycle.not_closed.with_distributor(current_distributor) end - enterprises = current_distributor.plus_relatives_and_oc_producers(order_cycles).activated.includes(address: :state).all + enterprises = current_distributor + .plus_relatives_and_oc_producers(order_cycles) + .activated + .includes(address: :state) + .all enterprises = inject_json_ams('enterprises', enterprises) render locals: { enterprises: enterprises } From e3edb51d3e974128e433b3cd6c0df82771cc4148 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 2 Jan 2019 13:46:24 +0100 Subject: [PATCH 4/6] Update rubocop_todo --- .rubocop_todo.yml | 142 ++++++++++++++-------------------------------- 1 file changed, 43 insertions(+), 99 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e8b203c9d6..38fa7f623d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 1400` -# on 2018-10-25 13:57:32 +1100 using RuboCop version 0.57.2. +# on 2019-01-02 13:44:41 +0100 using RuboCop version 0.57.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -27,7 +27,7 @@ Layout/AlignArray: - 'spec/lib/open_food_network/order_grouper_spec.rb' - 'spec/services/cart_service_spec.rb' -# Offense count: 121 +# Offense count: 122 # Cop supports --auto-correct. # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. # SupportedHashRocketStyles: key, separator, table @@ -56,8 +56,9 @@ Layout/AlignHash: - 'spec/models/order_cycle_spec.rb' - 'spec/models/spree/shipping_method_spec.rb' - 'spec/models/spree/variant_spec.rb' + - 'spec/models/variant_override_spec.rb' -# Offense count: 60 +# Offense count: 49 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: with_first_parameter, with_fixed_indentation @@ -68,7 +69,6 @@ Layout/AlignParameters: - 'app/models/enterprise_group.rb' - 'app/models/enterprise_relationship.rb' - 'app/serializers/api/address_serializer.rb' - - 'app/serializers/api/enterprise_serializer.rb' - 'app/serializers/api/shipping_method_serializer.rb' - 'lib/spree/product_filters.rb' - 'spec/controllers/enterprises_controller_spec.rb' @@ -94,11 +94,12 @@ Layout/BlockAlignment: - 'spec/models/spree/line_item_spec.rb' - 'spec/models/spree/product_spec.rb' -# Offense count: 1 +# Offense count: 2 # Cop supports --auto-correct. Layout/BlockEndNewline: Exclude: - 'spec/features/consumer/shopping/cart_spec.rb' + - 'spec/models/variant_override_spec.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -124,7 +125,7 @@ Layout/ElseAlignment: - 'app/serializers/api/admin/order_cycle_serializer.rb' - 'lib/open_food_network/sales_tax_report.rb' -# Offense count: 197 +# Offense count: 187 # Cop supports --auto-correct. Layout/EmptyLines: Exclude: @@ -137,7 +138,6 @@ Layout/EmptyLines: - 'app/controllers/spree/admin/adjustments_controller_decorator.rb' - 'app/controllers/spree/admin/base_controller_decorator.rb' - 'app/controllers/spree/admin/general_settings_controller_decorator.rb' - - 'app/controllers/spree/admin/orders_controller_decorator.rb' - 'app/controllers/spree/admin/payments_controller_decorator.rb' - 'app/controllers/spree/admin/products_controller_decorator.rb' - 'app/controllers/spree/admin/variants_controller_decorator.rb' @@ -148,10 +148,8 @@ Layout/EmptyLines: - 'app/jobs/finalize_account_invoices.rb' - 'app/jobs/products_cache_integrity_checker_job.rb' - 'app/jobs/refresh_products_cache_job.rb' - - 'app/mailers/producer_mailer.rb' - 'app/models/coordinator_fee.rb' - 'app/models/enterprise_fee.rb' - - 'app/models/enterprise_relationship.rb' - 'app/models/exchange.rb' - 'app/models/exchange_fee.rb' - 'app/models/inventory_item.rb' @@ -176,7 +174,6 @@ Layout/EmptyLines: - 'app/models/spree/shipping_method_decorator.rb' - 'app/models/spree/tax_rate_decorator.rb' - 'app/models/spree/taxon_decorator.rb' - - 'app/serializers/api/enterprise_serializer.rb' - 'lib/open_food_network/cached_products_renderer.rb' - 'lib/open_food_network/enterprise_fee_applicator.rb' - 'lib/open_food_network/enterprise_issue_validator.rb' @@ -188,7 +185,6 @@ Layout/EmptyLines: - 'lib/open_food_network/products_cache.rb' - 'lib/open_food_network/products_cache_integrity_checker.rb' - 'lib/open_food_network/products_renderer.rb' - - 'lib/open_food_network/property_merge.rb' - 'lib/open_food_network/reports/bulk_coop_report.rb' - 'lib/open_food_network/sales_tax_report.rb' - 'lib/open_food_network/scope_product_to_hub.rb' @@ -246,7 +242,6 @@ Layout/EmptyLines: - 'spec/models/spree/product_spec.rb' - 'spec/models/spree/shipping_method_spec.rb' - 'spec/models/spree/variant_spec.rb' - - 'spec/models/variant_override_spec.rb' - 'spec/serializers/admin/exchange_serializer_spec.rb' - 'spec/serializers/admin/for_order_cycle/enterprise_serializer_spec.rb' - 'spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb' @@ -261,15 +256,13 @@ Layout/EmptyLinesAroundArguments: Exclude: - 'spec/archive/features/consumer/checkout_spec.rb' -# Offense count: 59 +# Offense count: 51 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: empty_lines, no_empty_lines Layout/EmptyLinesAroundBlockBody: Exclude: - - 'app/controllers/spree/admin/orders_controller_decorator.rb' - 'app/controllers/spree/api/orders_controller_decorator.rb' - - 'app/controllers/spree/api/products_controller_decorator.rb' - 'app/controllers/spree/checkout_controller_decorator.rb' - 'app/models/spree/calculator/default_tax_decorator.rb' - 'app/models/spree/calculator_decorator.rb' @@ -279,21 +272,17 @@ Layout/EmptyLinesAroundBlockBody: - 'lib/spree/money_decorator.rb' - 'spec/controllers/admin/order_cycles_controller_spec.rb' - 'spec/controllers/admin/tag_rules_controller_spec.rb' - - 'spec/controllers/spree/admin/orders_controller_spec.rb' - 'spec/controllers/spree/admin/reports_controller_spec.rb' - 'spec/controllers/spree/api/orders_controller_spec.rb' - 'spec/controllers/spree/orders_controller_spec.rb' - 'spec/controllers/user_confirmations_controller_spec.rb' - - 'spec/controllers/user_registrations_controller_spec.rb' - 'spec/features/admin/caching_spec.rb' - 'spec/features/admin/orders_spec.rb' - 'spec/features/admin/reports_spec.rb' - - 'spec/features/admin/variant_overrides_spec.rb' - 'spec/features/consumer/cookies_spec.rb' - 'spec/features/consumer/shopping/embedded_groups_spec.rb' - 'spec/features/consumer/shopping/embedded_shopfronts_spec.rb' - 'spec/features/consumer/shopping/shopping_spec.rb' - - 'spec/features/consumer/shopping/variant_overrides_spec.rb' - 'spec/helpers/admin/business_model_configuration_helper_spec.rb' - 'spec/helpers/shared_helper_spec.rb' - 'spec/helpers/shop_helper_spec.rb' @@ -317,7 +306,7 @@ Layout/EmptyLinesAroundBlockBody: - 'spec/support/matchers/select2_matchers.rb' - 'spec/support/matchers/table_matchers.rb' -# Offense count: 24 +# Offense count: 23 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only @@ -331,7 +320,6 @@ Layout/EmptyLinesAroundClassBody: - 'app/controllers/api/enterprises_controller.rb' - 'app/controllers/application_controller.rb' - 'app/controllers/home_controller.rb' - - 'app/mailers/producer_mailer.rb' - 'app/models/coordinator_fee.rb' - 'app/models/producer_property.rb' - 'app/models/spree/preferences/file_configuration.rb' @@ -358,7 +346,7 @@ Layout/EndAlignment: - 'app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb' - 'app/serializers/api/admin/order_cycle_serializer.rb' -# Offense count: 47 +# Offense count: 45 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. Layout/ExtraSpacing: @@ -368,7 +356,6 @@ Layout/ExtraSpacing: - 'app/helpers/admin/injection_helper.rb' - 'app/models/enterprise.rb' - 'app/models/spree/classification_decorator.rb' - - 'app/serializers/api/enterprise_serializer.rb' - 'config.ru' - 'lib/open_food_network/bulk_coop_report.rb' - 'lib/open_food_network/option_value_namer.rb' @@ -453,7 +440,7 @@ Layout/IndentationWidth: - 'spec/models/enterprise_spec.rb' - 'spec/models/spree/calculator/flexi_rate_spec.rb' -# Offense count: 44 +# Offense count: 43 # Cop supports --auto-correct. Layout/LeadingCommentSpace: Exclude: @@ -463,7 +450,6 @@ Layout/LeadingCommentSpace: - 'app/models/spree/inventory_unit_decorator.rb' - 'app/models/spree/taxon_decorator.rb' - 'app/serializers/api/address_serializer.rb' - - 'app/serializers/api/enterprise_serializer.rb' - 'app/serializers/api/product_serializer.rb' - 'spec/archive/features/consumer/checkout_spec.rb' - 'spec/controllers/spree/api/line_items_controller_spec.rb' @@ -479,7 +465,7 @@ Layout/LeadingCommentSpace: - 'spec/support/matchers/select2_matchers.rb' - 'spec/support/request/authentication_workflow.rb' -# Offense count: 44 +# Offense count: 45 # Cop supports --auto-correct. Layout/MultilineBlockLayout: Exclude: @@ -499,6 +485,7 @@ Layout/MultilineBlockLayout: - 'spec/models/order_cycle_spec.rb' - 'spec/models/spree/product_spec.rb' - 'spec/models/spree/variant_spec.rb' + - 'spec/models/variant_override_spec.rb' - 'spec/serializers/enterprise_serializer_spec.rb' # Offense count: 4 @@ -645,7 +632,7 @@ Layout/SpaceAroundEqualsInParameterDefault: - 'spec/support/request/distribution_helper.rb' - 'spec/support/request/web_helper.rb' -# Offense count: 55 +# Offense count: 50 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment. Layout/SpaceAroundOperators: @@ -656,7 +643,6 @@ Layout/SpaceAroundOperators: - 'app/overrides/remove_search_bar.rb' - 'app/overrides/remove_side_bar.rb' - 'app/overrides/replace_shipping_address_form_with_distributor_details.rb' - - 'app/serializers/api/enterprise_serializer.rb' - 'lib/open_food_network/xero_invoices_report.rb' - 'lib/spree/product_filters.rb' - 'spec/controllers/admin/enterprises_controller_spec.rb' @@ -721,7 +707,7 @@ Layout/SpaceInsideArrayLiteralBrackets: - 'spec/lib/open_food_network/users_and_enterprises_report_spec.rb' - 'spec/models/spree/order_spec.rb' -# Offense count: 194 +# Offense count: 192 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. # SupportedStyles: space, no_space @@ -774,7 +760,7 @@ Layout/SpaceInsideBlockBraces: - 'spec/spec_helper.rb' - 'spec/support/cancan_helper.rb' -# Offense count: 728 +# Offense count: 702 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. # SupportedStyles: space, no_space, compact @@ -922,7 +908,7 @@ Layout/TrailingBlankLines: Exclude: - 'spec/controllers/cart_controller_spec.rb' -# Offense count: 60 +# Offense count: 57 # Cop supports --auto-correct. # Configuration parameters: AllowInHeredoc. Layout/TrailingWhitespace: @@ -938,7 +924,6 @@ Layout/TrailingWhitespace: - 'app/views/json/partials/_producer.rabl' - 'spec/controllers/admin/column_preferences_controller_spec.rb' - 'spec/features/admin/customers_spec.rb' - - 'spec/features/admin/variant_overrides_spec.rb' - 'spec/features/consumer/cookies_spec.rb' - 'spec/helpers/enterprises_helper_spec.rb' - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb' @@ -951,9 +936,10 @@ Layout/TrailingWhitespace: - 'spec/serializers/enterprise_serializer_spec.rb' - 'spec/support/request/menu_helper.rb' -# Offense count: 1 +# Offense count: 2 Lint/AmbiguousOperator: Exclude: + - 'spec/controllers/api/enterprise_fees_controller_spec.rb' - 'spec/controllers/spree/admin/payments_controller_spec.rb' # Offense count: 4 @@ -962,14 +948,13 @@ Lint/DuplicateMethods: - 'lib/discourse/single_sign_on.rb' - 'lib/open_food_network/subscription_summary.rb' -# Offense count: 16 +# Offense count: 15 Lint/IneffectiveAccessModifier: Exclude: - 'app/models/column_preference.rb' - 'app/models/variant_override.rb' - 'lib/open_food_network/feature_toggle.rb' - 'lib/open_food_network/products_cache.rb' - - 'lib/open_food_network/property_merge.rb' - 'spec/lib/open_food_network/reports/report_spec.rb' # Offense count: 2 @@ -1069,18 +1054,17 @@ Lint/UnusedMethodArgument: - 'lib/open_food_network/paperclippable.rb' - 'lib/open_food_network/rack_request_blocker.rb' -# Offense count: 6 +# Offense count: 5 # Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. Lint/UselessAccessModifier: Exclude: - 'app/models/column_preference.rb' - 'lib/open_food_network/feature_toggle.rb' - 'lib/open_food_network/products_cache.rb' - - 'lib/open_food_network/property_merge.rb' - 'lib/open_food_network/reports/bulk_coop_report.rb' - 'spec/lib/open_food_network/reports/report_spec.rb' -# Offense count: 242 +# Offense count: 240 # Configuration parameters: CheckForMethodsWithNoSideEffects. Lint/Void: Exclude: @@ -1091,7 +1075,6 @@ Lint/Void: - 'spec/controllers/enterprises_controller_spec.rb' - 'spec/controllers/shop_controller_spec.rb' - 'spec/controllers/spree/admin/adjustments_controller_spec.rb' - - 'spec/controllers/spree/admin/orders_controller_spec.rb' - 'spec/controllers/spree/admin/variants_controller_spec.rb' - 'spec/controllers/spree/api/products_controller_spec.rb' - 'spec/controllers/spree/api/variants_controller_spec.rb' @@ -1135,53 +1118,26 @@ Lint/Void: - 'spec/serializers/enterprise_serializer_spec.rb' - 'spec/support/request/web_helper.rb' -# Offense count: 192 -Metrics/AbcSize: - Max: 293 - -# Offense count: 1039 +# Offense count: 110 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: Max: 787 # Offense count: 1 -# Configuration parameters: CountBlocks. -Metrics/BlockNesting: - Max: 4 - -# Offense count: 23 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 331 + Max: 117 -# Offense count: 36 -Metrics/CyclomaticComplexity: - Max: 23 - -# Offense count: 2717 +# Offense count: 1 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: - Max: 619 + Max: 141 -# Offense count: 161 +# Offense count: 1 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 95 - -# Offense count: 27 -# Configuration parameters: CountComments. -Metrics/ModuleLength: - Max: 633 - -# Offense count: 6 -# Configuration parameters: CountKeywordArgs. -Metrics/ParameterLists: - Max: 8 - -# Offense count: 28 -Metrics/PerceivedComplexity: - Max: 21 + Max: 14 # Offense count: 7 Naming/AccessorMethodName: @@ -1236,7 +1192,7 @@ Naming/PredicateName: - 'lib/open_food_network/packing_report.rb' - 'lib/tasks/data.rake' -# Offense count: 13 +# Offense count: 12 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. # AllowedNames: io, id, to, by, on, in, at Naming/UncommunicativeMethodParamName: @@ -1246,7 +1202,6 @@ Naming/UncommunicativeMethodParamName: - 'app/helpers/spree/base_helper_decorator.rb' - 'app/models/exchange.rb' - 'app/services/subscription_validator.rb' - - 'lib/open_food_network/property_merge.rb' - 'lib/open_food_network/reports/bulk_coop_report.rb' - 'lib/open_food_network/xero_invoices_report.rb' - 'spec/lib/open_food_network/reports/report_spec.rb' @@ -1259,7 +1214,7 @@ Naming/VariableName: Exclude: - 'app/helpers/admin/injection_helper.rb' -# Offense count: 16 +# Offense count: 10 # Configuration parameters: EnforcedStyle. # SupportedStyles: snake_case, normalcase, non_integer Naming/VariableNumber: @@ -1417,7 +1372,7 @@ Rails/HasManyOrHasOneDependent: - 'app/models/spree/variant_decorator.rb' - 'app/models/subscription.rb' -# Offense count: 45 +# Offense count: 46 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: numeric, symbolic @@ -1426,13 +1381,13 @@ Rails/HttpStatus: - 'app/controllers/admin/bulk_line_items_controller.rb' - 'app/controllers/admin/column_preferences_controller.rb' - 'app/controllers/admin/customers_controller.rb' - - 'app/controllers/admin/enterprise_fees_controller.rb' - 'app/controllers/admin/enterprise_relationships_controller.rb' - 'app/controllers/admin/enterprise_roles_controller.rb' - 'app/controllers/admin/manager_invitations_controller.rb' - 'app/controllers/admin/tag_rules_controller.rb' - 'app/controllers/admin/variant_overrides_controller.rb' - 'app/controllers/api/customers_controller.rb' + - 'app/controllers/api/enterprise_fees_controller.rb' - 'app/controllers/api/enterprises_controller.rb' - 'app/controllers/application_controller.rb' - 'app/controllers/cart_controller.rb' @@ -1473,12 +1428,11 @@ Rails/Presence: Exclude: - 'app/serializers/api/admin/customer_serializer.rb' -# Offense count: 4 +# Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank. Rails/Present: Exclude: - - 'app/controllers/spree/admin/orders_controller_decorator.rb' - 'app/models/producer_property.rb' - 'lib/open_food_network/products_and_inventory_report.rb' @@ -1655,7 +1609,7 @@ Style/CaseEquality: - 'app/helpers/angular_form_helper.rb' - 'spec/models/spree/payment_spec.rb' -# Offense count: 85 +# Offense count: 82 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: nested, compact @@ -1799,7 +1753,7 @@ Style/EmptyLiteral: - 'app/helpers/checkout_helper.rb' - 'app/models/spree/order_decorator.rb' -# Offense count: 6 +# Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: compact, expanded @@ -1809,7 +1763,6 @@ Style/EmptyMethod: - 'app/controllers/home_controller.rb' - 'app/controllers/map_controller.rb' - 'app/controllers/producers_controller.rb' - - 'app/controllers/shops_controller.rb' - 'app/controllers/spree/admin/products_controller_decorator.rb' # Offense count: 2 @@ -1828,19 +1781,17 @@ Style/FormatStringToken: - 'lib/open_food_network/sales_tax_report.rb' - 'spec/models/enterprise_spec.rb' -# Offense count: 80 +# Offense count: 76 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: - 'app/controllers/admin/accounts_and_billing_settings_controller.rb' - - 'app/controllers/admin/enterprise_fees_controller.rb' - 'app/controllers/admin/enterprises_controller.rb' - 'app/controllers/admin/order_cycles_controller.rb' - 'app/controllers/admin/product_import_controller.rb' - 'app/controllers/application_controller.rb' - 'app/controllers/base_controller.rb' - 'app/controllers/checkout_controller.rb' - - 'app/controllers/enterprises_controller.rb' - 'app/controllers/home_controller.rb' - 'app/controllers/spree/admin/adjustments_controller_decorator.rb' - 'app/controllers/spree/admin/base_controller_decorator.rb' @@ -1853,7 +1804,6 @@ Style/GuardClause: - 'app/jobs/products_cache_integrity_checker_job.rb' - 'app/jobs/update_account_invoices.rb' - 'app/jobs/update_billable_periods.rb' - - 'app/mailers/producer_mailer.rb' - 'app/models/enterprise.rb' - 'app/models/enterprise_group.rb' - 'app/models/producer_property.rb' @@ -1876,7 +1826,7 @@ Style/GuardClause: - 'spec/support/request/distribution_helper.rb' - 'spec/support/request/shop_workflow.rb' -# Offense count: 924 +# Offense count: 872 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys @@ -1908,7 +1858,6 @@ Style/HashSyntax: - 'app/helpers/spree/admin/navigation_helper_decorator.rb' - 'app/helpers/spree/admin/orders_helper_decorator.rb' - 'app/mailers/enterprise_mailer.rb' - - 'app/mailers/spree/order_mailer_decorator.rb' - 'app/mailers/spree/user_mailer_decorator.rb' - 'app/models/billable_period.rb' - 'app/models/calculator/flat_percent_per_item.rb' @@ -1947,7 +1896,6 @@ Style/HashSyntax: - 'app/overrides/set_auth_token_in_frontend.rb' - 'app/presenters/variant_presenter.rb' - 'app/serializers/api/admin/enterprise_fee_serializer.rb' - - 'app/serializers/api/enterprise_serializer.rb' - 'app/views/api/order_cycles/bulk_show.v1.rabl' - 'app/views/json/_order_cycle.rabl' - 'app/views/json/partials/_hub.rabl' @@ -1972,7 +1920,6 @@ Style/HashSyntax: - 'spec/controllers/api/order_cycles_controller_spec.rb' - 'spec/controllers/base_controller_spec.rb' - 'spec/controllers/cart_controller_spec.rb' - - 'spec/controllers/spree/admin/orders_controller_spec.rb' - 'spec/controllers/spree/admin/payment_methods_controller_spec.rb' - 'spec/controllers/spree/admin/payments_controller_spec.rb' - 'spec/controllers/spree/api/products_controller_spec.rb' @@ -2161,7 +2108,7 @@ Style/NumericLiteralPrefix: Exclude: - 'spec/features/admin/order_cycles_spec.rb' -# Offense count: 13 +# Offense count: 12 # Cop supports --auto-correct. # Configuration parameters: Strict. Style/NumericLiterals: @@ -2198,14 +2145,13 @@ Style/ParenthesesAroundCondition: Exclude: - 'app/controllers/checkout_controller.rb' -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: short, verbose Style/PreferredHashMethods: Exclude: - 'app/controllers/spree/orders_controller_decorator.rb' - - 'spec/controllers/spree/admin/orders_controller_spec.rb' # Offense count: 18 # Cop supports --auto-correct. @@ -2263,7 +2209,7 @@ Style/RedundantReturn: - 'app/models/spree/classification_decorator.rb' - 'app/serializers/api/admin/enterprise_serializer.rb' -# Offense count: 96 +# Offense count: 95 # Cop supports --auto-correct. Style/RedundantSelf: Exclude: @@ -2310,15 +2256,14 @@ Style/RegexpLiteral: - 'spec/mailers/subscription_mailer_spec.rb' - 'spec/models/content_configuration_spec.rb' -# Offense count: 4 +# Offense count: 2 # Cop supports --auto-correct. Style/RescueModifier: Exclude: - 'app/controllers/application_controller.rb' - - 'app/controllers/spree/admin/orders_controller_decorator.rb' - 'lib/tasks/data.rake' -# Offense count: 268 +# Offense count: 266 Style/Send: Exclude: - 'spec/controllers/admin/subscriptions_controller_spec.rb' @@ -2394,7 +2339,7 @@ Style/StructInheritance: Exclude: - 'lib/open_food_network/enterprise_fee_applicator.rb' -# Offense count: 93 +# Offense count: 90 # Cop supports --auto-correct. # Configuration parameters: IgnoredMethods. # IgnoredMethods: respond_to, define_method @@ -2418,7 +2363,6 @@ Style/SymbolProc: - 'lib/open_food_network/reports/bulk_coop_supplier_report.rb' - 'lib/spree/product_filters.rb' - 'spec/controllers/api/order_cycles_controller_spec.rb' - - 'spec/controllers/spree/admin/orders_controller_spec.rb' - 'spec/controllers/spree/api/products_controller_spec.rb' - 'spec/controllers/spree/api/variants_controller_spec.rb' - 'spec/features/admin/bulk_product_update_spec.rb' From ddf916814f02617310a4bac9fd9df5f720e1ebe4 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 3 Jan 2019 11:14:51 +0100 Subject: [PATCH 5/6] 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 From edffbd72fe961efc3886055c230d3e9ed874dd4c Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 3 Jan 2019 11:15:52 +0100 Subject: [PATCH 6/6] Update rubocop_manual_todo --- .rubocop_manual_todo.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index 390010ef06..71812eb60a 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -47,7 +47,6 @@ Metrics/LineLength: - app/controllers/base_controller.rb - app/controllers/cart_controller.rb - app/controllers/checkout_controller.rb - - app/controllers/enterprises_controller.rb - app/controllers/shop_controller.rb - app/controllers/spree/admin/adjustments_controller_decorator.rb - app/controllers/spree/admin/base_controller_decorator.rb @@ -435,7 +434,6 @@ Metrics/AbcSize: - app/controllers/cart_controller.rb - app/controllers/checkout_controller.rb - app/controllers/discourse_sso_controller.rb - - app/controllers/enterprises_controller.rb - app/controllers/spree/admin/adjustments_controller_decorator.rb - app/controllers/spree/admin/line_items_controller_decorator.rb - app/controllers/spree/admin/orders_controller_decorator.rb