Skip to content

Commit

Permalink
Merge pull request #52185 from Shopify/vs/turn_action_controller_incl…
Browse files Browse the repository at this point in the history
…usions_explicit

Turn ActionController::Base inclusions explicit
  • Loading branch information
rafaelfranca committed Jun 21, 2024
2 parents 3a2ec9b + 0966b19 commit 5cfa136
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
58 changes: 43 additions & 15 deletions actionpack/lib/action_controller/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ def self.without_modules(*modules)
AbstractController::Rendering,
AbstractController::Translation,
AbstractController::AssetPaths,

Helpers,
UrlFor,
Redirecting,
Expand Down Expand Up @@ -261,26 +260,55 @@ def self.without_modules(*modules)
HttpAuthentication::Token::ControllerMethods,
DefaultHeaders,
Logging,

# Before callbacks should also be executed as early as possible, so also include
# them at the bottom.
AbstractController::Callbacks,

# Append rescue at the bottom to wrap as much as possible.
Rescue,

# Add instrumentations hooks at the bottom, to ensure they instrument all the
# methods properly.
Instrumentation,

# Params wrapper should come before instrumentation so they are properly showed
# in logs
ParamsWrapper
]

MODULES.each do |mod|
include mod
end
include AbstractController::Rendering
include AbstractController::Translation
include AbstractController::AssetPaths
include Helpers
include UrlFor
include Redirecting
include ActionView::Layouts
include Rendering
include Renderers::All
include ConditionalGet
include EtagWithTemplateDigest
include EtagWithFlash
include Caching
include MimeResponds
include ImplicitRender
include StrongParameters
include ParameterEncoding
include Cookies
include Flash
include FormBuilder
include RequestForgeryProtection
include ContentSecurityPolicy
include PermissionsPolicy
include RateLimiting
include AllowBrowser
include Streaming
include DataStreaming
include HttpAuthentication::Basic::ControllerMethods
include HttpAuthentication::Digest::ControllerMethods
include HttpAuthentication::Token::ControllerMethods
include DefaultHeaders
include Logging
# Before callbacks should also be executed as early as possible, so also include
# them at the bottom.
include AbstractController::Callbacks
# Append rescue at the bottom to wrap as much as possible.
include Rescue
# Add instrumentations hooks at the bottom, to ensure they instrument all the
# methods properly.
include Instrumentation
# Params wrapper should come before instrumentation so they are properly showed
# in logs
include ParamsWrapper
setup_renderer!

# Define some internal variables that should not be propagated to the view.
Expand Down
12 changes: 12 additions & 0 deletions actionpack/test/controller/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,15 @@ def test_named_routes_with_path_without_doing_a_request_first
end
end
end

class BaseTest < ActiveSupport::TestCase
def test_included_modules_are_tracked
base_content = File.read("#{__dir__}/../../lib/action_controller/base.rb")
included_modules = base_content.scan(/(?<=include )[A-Z].*/)

assert_equal(
ActionController::Base::MODULES.map { |m| m.to_s.delete_prefix("ActionController::") },
included_modules
)
end
end

0 comments on commit 5cfa136

Please sign in to comment.