From de02e88494728b1b209f0b0f0581e8e509212d51 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 22 Dec 2023 18:25:05 +0100 Subject: [PATCH 1/2] Remove unused action in controller callbacks With Rails 7.1, callbacks only work with actions that are defined on the controller. This check allowed us to notice we had this some no more used actions. This commit also enable the new configuration in the dummy app so we will be able to spot new errors. The configuration needs to be defined explicitely because it's not part of the load_defaults but it's copied in the dummy application directly. Took advantage of the change for adding another 7.1-only configuration to the dummy app: config.action_dispatch.show_exceptions = :none --- .../controllers/spree/api/customer_returns_controller.rb | 2 +- api/app/controllers/spree/api/payments_controller.rb | 4 ++-- api/app/controllers/spree/api/stock_movements_controller.rb | 2 +- .../app/controllers/spree/admin/adjustments_controller.rb | 2 +- core/lib/spree/testing_support/dummy_app.rb | 6 ++++++ 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/api/app/controllers/spree/api/customer_returns_controller.rb b/api/app/controllers/spree/api/customer_returns_controller.rb index 6999c44aade..fc16de5dc0a 100644 --- a/api/app/controllers/spree/api/customer_returns_controller.rb +++ b/api/app/controllers/spree/api/customer_returns_controller.rb @@ -5,7 +5,7 @@ module Api class CustomerReturnsController < Spree::Api::BaseController before_action :load_order before_action :build_customer_return, only: [:create] - around_action :lock_order, only: [:create, :update, :destroy, :cancel] + around_action :lock_order, only: [:create, :update] rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error diff --git a/api/app/controllers/spree/api/payments_controller.rb b/api/app/controllers/spree/api/payments_controller.rb index 81fc16bca7f..ca6bea4ae47 100644 --- a/api/app/controllers/spree/api/payments_controller.rb +++ b/api/app/controllers/spree/api/payments_controller.rb @@ -4,8 +4,8 @@ module Spree module Api class PaymentsController < Spree::Api::BaseController before_action :find_order - around_action :lock_order, only: [:create, :update, :destroy, :authorize, :capture, :purchase, :void, :credit] - before_action :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void, :credit] + around_action :lock_order, only: [:create, :update, :authorize, :capture, :purchase, :void] + before_action :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void] def index @payments = paginate(@order.payments.ransack(params[:q]).result) diff --git a/api/app/controllers/spree/api/stock_movements_controller.rb b/api/app/controllers/spree/api/stock_movements_controller.rb index d6946f77d2a..164f25a2174 100644 --- a/api/app/controllers/spree/api/stock_movements_controller.rb +++ b/api/app/controllers/spree/api/stock_movements_controller.rb @@ -3,7 +3,7 @@ module Spree module Api class StockMovementsController < Spree::Api::BaseController - before_action :stock_location, except: [:update, :destroy] + before_action :stock_location def index authorize! :index, StockMovement diff --git a/backend/app/controllers/spree/admin/adjustments_controller.rb b/backend/app/controllers/spree/admin/adjustments_controller.rb index 1c8e9f4d3a9..bbd6b363764 100644 --- a/backend/app/controllers/spree/admin/adjustments_controller.rb +++ b/backend/app/controllers/spree/admin/adjustments_controller.rb @@ -9,7 +9,7 @@ class AdjustmentsController < ResourceController destroy.after :update_totals update.after :update_totals - skip_before_action :load_resource, only: [:toggle_state, :edit, :update, :destroy] + skip_before_action :load_resource, only: [:edit, :update, :destroy] before_action :find_adjustment, only: [:destroy, :edit, :update] diff --git a/core/lib/spree/testing_support/dummy_app.rb b/core/lib/spree/testing_support/dummy_app.rb index 45f3735bae9..f78ebf645e9 100644 --- a/core/lib/spree/testing_support/dummy_app.rb +++ b/core/lib/spree/testing_support/dummy_app.rb @@ -45,6 +45,12 @@ def self.setup(gem_root:, lib_name:, auto_migrate: true) class Application < ::Rails::Application config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}") + + if Rails.gem_version >= Gem::Version.new('7.1') + config.action_controller.raise_on_missing_callback_actions = true + config.action_dispatch.show_exceptions = :none + end + # Make the test environment more production-like: config.action_controller.allow_forgery_protection = false config.action_controller.default_protect_from_forgery = false From 7a3b599e553a3130797316a8908b2643f6c76f71 Mon Sep 17 00:00:00 2001 From: Rainer Dema Date: Fri, 22 Dec 2023 19:17:35 +0100 Subject: [PATCH 2/2] Remove unused `load_promotion_category` method and callback Removed the load_promotion_category method and its corresponding before_action for the non-existent :move action. --- .../solidus_admin/promotion_categories_controller.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/admin/app/controllers/solidus_admin/promotion_categories_controller.rb b/admin/app/controllers/solidus_admin/promotion_categories_controller.rb index e258cc7609b..b7f4f8fdb6c 100644 --- a/admin/app/controllers/solidus_admin/promotion_categories_controller.rb +++ b/admin/app/controllers/solidus_admin/promotion_categories_controller.rb @@ -4,8 +4,6 @@ module SolidusAdmin class PromotionCategoriesController < SolidusAdmin::BaseController include SolidusAdmin::ControllerHelpers::Search - before_action :load_promotion_category, only: [:move] - def index promotion_categories = apply_search_to( Spree::PromotionCategory.all, @@ -27,12 +25,5 @@ def destroy flash[:notice] = t('.success') redirect_back_or_to promotion_categories_path, status: :see_other end - - private - - def load_promotion_category - @promotion_category = Spree::PromotionCategory.find(params[:id]) - authorize! action_name, @promotion_category - end end end