Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unused action in controller callbacks
Browse files Browse the repository at this point in the history
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
kennyadsl committed Dec 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b141cf8 commit ff56ef0
Showing 5 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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

6 changes: 2 additions & 4 deletions api/app/controllers/spree/api/payments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# frozen_string_literal: true

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)
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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]

6 changes: 6 additions & 0 deletions core/lib/spree/testing_support/dummy_app.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ff56ef0

Please sign in to comment.