From 2808a41f0d95c01e470deb65d0750e0a40ca23ca Mon Sep 17 00:00:00 2001 From: David Thomas Date: Thu, 26 Feb 2026 15:35:55 -0500 Subject: [PATCH] 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