From 708dbb22709e22cb2ceeb69a6ac615e818128dc5 Mon Sep 17 00:00:00 2001 From: David Thomas Date: Thu, 26 Feb 2026 15:33:37 -0500 Subject: [PATCH 1/3] Regenerate Rubocop's TODO file --- .rubocop_todo.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 130d414236..e2d6ddbe75 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400 --no-auto-gen-timestamp` -# using RuboCop version 1.81.7. +# using RuboCop version 1.84.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 @@ -35,6 +35,7 @@ Lint/UselessConstantScoping: - 'lib/reporting/report_metadata_builder.rb' # Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). Lint/UselessOr: Exclude: - 'app/models/product_import/entry_validator.rb' @@ -62,14 +63,13 @@ Metrics/AbcSize: - 'lib/spree/core/controller_helpers/order.rb' - 'spec/services/orders/checkout_restart_service_spec.rb' -# Offense count: 9 +# Offense count: 7 # Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. # AllowedMethods: refine Metrics/BlockLength: Exclude: - 'app/models/spree/order/checkout.rb' - 'app/models/spree/payment.rb' - - 'app/models/spree/payment/processing.rb' - 'app/models/spree/shipment.rb' - 'lib/spree/core/controller_helpers/common.rb' - 'lib/tasks/data.rake' @@ -168,7 +168,7 @@ Metrics/CyclomaticComplexity: - 'lib/spree/localized_number.rb' - 'spec/models/product_importer_spec.rb' -# Offense count: 22 +# Offense count: 20 # Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Exclude: @@ -178,7 +178,6 @@ Metrics/MethodLength: - 'app/models/spree/ability.rb' - 'app/models/spree/gateway/pay_pal_express.rb' - 'app/models/spree/order/checkout.rb' - - 'app/models/spree/payment/processing.rb' - 'app/models/spree/preferences/preferable_class_methods.rb' - 'lib/open_food_network/order_cycle_form_applicator.rb' - 'lib/open_food_network/order_cycle_permissions.rb' @@ -238,7 +237,7 @@ Naming/MethodParameterName: # Offense count: 60 # Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates. # AllowedMethods: call -# WaywardPredicates: nonzero? +# WaywardPredicates: infinite?, nonzero? Naming/PredicateMethod: Exclude: - 'app/controllers/admin/product_import_controller.rb' @@ -345,7 +344,6 @@ Rails/Presence: # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Severity. Rails/RedirectBackOrTo: Exclude: - 'app/controllers/admin/order_cycles_controller.rb' From 18869979db93636abc3035ec04aacec25f7c8a69 Mon Sep 17 00:00:00 2001 From: David Thomas Date: Thu, 26 Feb 2026 15:34:45 -0500 Subject: [PATCH 2/3] Safely autocorrect Rails/Presence Inspecting 1721 files ...................................C.................................................................................................................................................................................................................................................................................................................................................C................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Offenses: app/controllers/admin/enterprises_controller.rb:180:7: C: [Corrected] Rails/Presence: Use @object.custom_tab.presence&.destroy instead of @object.custom_tab.destroy if @object.custom_tab.present?. @object.custom_tab.destroy if @object.custom_tab.present? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/controllers/admin/enterprises_controller.rb:243:9: C: [Corrected] Rails/Presence: Use (enterprises.presence&.includes(supplied_products: [:variants, :image])) instead of if enterprises.present? ... end. if enterprises.present? ... ^^^^^^^^^^^^^^^^^^^^^^^ app/controllers/admin/enterprises_controller.rb:243:9: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a method call. (enterprises.presence&.includes(supplied_products: [:variants, :image])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/models/spree/product.rb:298:7: C: [Corrected] Rails/Presence: Use (first_variant.supplier.presence&.touch) instead of first_variant.supplier.touch if first_variant.supplier.present?. first_variant.supplier.touch if first_variant.supplier.present? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/models/spree/product.rb:298:7: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a method call. (first_variant.supplier.presence&.touch) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1721 files inspected, 5 offenses detected, 5 offenses corrected --- .rubocop_todo.yml | 7 ------- app/controllers/admin/enterprises_controller.rb | 6 ++---- app/models/spree/product.rb | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e2d6ddbe75..e41f3f6231 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -335,13 +335,6 @@ Rails/OrderArguments: - 'spec/services/orders/generate_invoice_service_spec.rb' - 'spec/system/admin/order_cycles/simple_spec.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Rails/Presence: - Exclude: - - 'app/controllers/admin/enterprises_controller.rb' - - 'app/models/spree/product.rb' - # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). Rails/RedirectBackOrTo: diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index de96364445..5d13ec0883 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -177,7 +177,7 @@ module Admin protected def delete_custom_tab - @object.custom_tab.destroy if @object.custom_tab.present? + @object.custom_tab.presence&.destroy enterprise_params.delete(:custom_tab_attributes) end @@ -240,9 +240,7 @@ module Admin enterprises = OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, @order_cycle) .visible_enterprises - if enterprises.present? - enterprises.includes(supplied_products: [:variants, :image]) - end + enterprises.presence&.includes(supplied_products: [:variants, :image]) when :index if spree_current_user.admin? OpenFoodNetwork::Permissions.new(spree_current_user). diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index e077af407b..f3cf46aeda 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -295,7 +295,7 @@ module Spree # The variant is invalid if no supplier is present, but this method can be triggered when # importing product. In this scenario the variant has not been updated with the supplier yet # hence the check. - first_variant.supplier.touch if first_variant.supplier.present? + first_variant.supplier.presence&.touch end def validate_image From 2808a41f0d95c01e470deb65d0750e0a40ca23ca Mon Sep 17 00:00:00 2001 From: David Thomas Date: Thu, 26 Feb 2026 15:35:55 -0500 Subject: [PATCH 3/3] Safely autocorrect Rails/RedirectBackOrTo Inspecting 1721 files ........................................W...................................................................W................W..W.......W................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ Offenses: app/controllers/admin/order_cycles_controller.rb:212:9: W: [Corrected] Rails/RedirectBackOrTo: Use redirect_back_or_to instead of redirect_back with :fallback_location keyword argument. redirect_back(fallback_location: root_path) ^^^^^^^^^^^^^ app/controllers/locales_controller.rb:6:5: W: [Corrected] Rails/RedirectBackOrTo: Use redirect_back_or_to instead of redirect_back with :fallback_location keyword argument. redirect_back fallback_location: main_app.root_url ^^^^^^^^^^^^^ app/controllers/spree/admin/invoices_controller.rb:31:9: W: [Corrected] Rails/RedirectBackOrTo: Use redirect_back_or_to instead of redirect_back with :fallback_location keyword argument. redirect_back(fallback_location: spree.admin_dashboard_path) ^^^^^^^^^^^^^ app/controllers/spree/admin/orders_controller.rb:83:9: W: [Corrected] Rails/RedirectBackOrTo: Use redirect_back_or_to instead of redirect_back with :fallback_location keyword argument. redirect_back fallback_location: spree.admin_dashboard_path ^^^^^^^^^^^^^ app/controllers/spree/admin/orders_controller.rb:91:25: W: [Corrected] Rails/RedirectBackOrTo: Use redirect_back_or_to instead of redirect_back with :fallback_location keyword argument. format.html { redirect_back(fallback_location: spree.admin_dashboard_path) } ^^^^^^^^^^^^^ app/controllers/spree/admin/return_authorizations_controller.rb:13:9: W: [Corrected] Rails/RedirectBackOrTo: Use redirect_back_or_to instead of redirect_back with :fallback_location keyword argument. redirect_back fallback_location: spree.admin_dashboard_path ^^^^^^^^^^^^^ 1721 files inspected, 6 offenses detected, 6 offenses corrected --- .rubocop_todo.yml | 10 ---------- app/controllers/admin/order_cycles_controller.rb | 2 +- app/controllers/locales_controller.rb | 2 +- app/controllers/spree/admin/invoices_controller.rb | 2 +- app/controllers/spree/admin/orders_controller.rb | 4 ++-- .../spree/admin/return_authorizations_controller.rb | 2 +- 6 files changed, 6 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e41f3f6231..5acf4e85e0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -335,16 +335,6 @@ Rails/OrderArguments: - 'spec/services/orders/generate_invoice_service_spec.rb' - 'spec/system/admin/order_cycles/simple_spec.rb' -# Offense count: 6 -# This cop supports safe autocorrection (--autocorrect). -Rails/RedirectBackOrTo: - Exclude: - - 'app/controllers/admin/order_cycles_controller.rb' - - 'app/controllers/locales_controller.rb' - - 'app/controllers/spree/admin/invoices_controller.rb' - - 'app/controllers/spree/admin/orders_controller.rb' - - 'app/controllers/spree/admin/return_authorizations_controller.rb' - # Offense count: 1 # Configuration parameters: TransactionMethods. Rails/TransactionExitStatement: diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 12a3a9fe5c..cec001aa4e 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -209,7 +209,7 @@ module Admin elsif params[:context] == "checkout_options" && params[:save_and_back_to_list] redirect_to main_app.admin_order_cycles_path else - redirect_back(fallback_location: root_path) + redirect_back_or_to(root_path) end end diff --git a/app/controllers/locales_controller.rb b/app/controllers/locales_controller.rb index bb18748a5d..238ef068c9 100644 --- a/app/controllers/locales_controller.rb +++ b/app/controllers/locales_controller.rb @@ -3,6 +3,6 @@ class LocalesController < BaseController def show UserLocaleSetter.new(spree_current_user, params[:id], cookies).set_locale - redirect_back fallback_location: main_app.root_url + redirect_back_or_to(main_app.root_url) end end diff --git a/app/controllers/spree/admin/invoices_controller.rb b/app/controllers/spree/admin/invoices_controller.rb index 91d637affd..ff3762f163 100644 --- a/app/controllers/spree/admin/invoices_controller.rb +++ b/app/controllers/spree/admin/invoices_controller.rb @@ -28,7 +28,7 @@ module Spree flash[:error] = t(:must_have_valid_business_number, enterprise_name: @order.distributor.name) end - redirect_back(fallback_location: spree.admin_dashboard_path) + redirect_back_or_to(spree.admin_dashboard_path) end private diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index b02ff61825..c7ef293d87 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -80,7 +80,7 @@ module Spree rescue Spree::Core::GatewayError => e flash[:error] = e.message.to_s ensure - redirect_back fallback_location: spree.admin_dashboard_path + redirect_back_or_to(spree.admin_dashboard_path) end def resend @@ -88,7 +88,7 @@ module Spree flash[:success] = t('admin.orders.order_email_resent') respond_with(@order) do |format| - format.html { redirect_back(fallback_location: spree.admin_dashboard_path) } + format.html { redirect_back_or_to(spree.admin_dashboard_path) } end end diff --git a/app/controllers/spree/admin/return_authorizations_controller.rb b/app/controllers/spree/admin/return_authorizations_controller.rb index 9e1d241559..6e462a23ec 100644 --- a/app/controllers/spree/admin/return_authorizations_controller.rb +++ b/app/controllers/spree/admin/return_authorizations_controller.rb @@ -10,7 +10,7 @@ module Spree def fire @return_authorization.public_send("#{params[:e]}!") flash[:success] = Spree.t(:return_authorization_updated) - redirect_back fallback_location: spree.admin_dashboard_path + redirect_back_or_to(spree.admin_dashboard_path) end protected