Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't force ActionController::TestCase to load #2460

Merged

Conversation

eugeneius
Copy link

Instead of referencing ActionController::TestCase directly during boot, we can use a lazy load hook to apply our mixins if it is loaded later.

Aside from the direct benefit of not evaluating a rather large Ruby file until necessary, this will avoid forcing other lazy load hooks to run prematurely (e.g. amatsuda/routes_lazy_routes#14).

The action_controller_test_case load hook was added in Rails 5.1, and the run_once option was added in Rails 5.2. I've left the behaviour unchanged for older Rails versions where they're not available.

Instead of referencing ActionController::TestCase directly during boot,
we can use a lazy load hook to apply our mixins if it is loaded later.

The action_controller_test_case load hook was added in Rails 5.1, and
the run_once option was added in Rails 5.2. I've left the behaviour
unchanged for older Rails versions where they're not available.
@bf4 bf4 merged commit bda1950 into rails-api:0-10-stable Feb 21, 2024
12 checks passed
@bf4
Copy link
Member

bf4 commented Feb 21, 2024

awesome, thanks

@@ -44,9 +44,19 @@ class Railtie < Rails::Railtie
end
# :nocov:

def extend_action_controller_test_case(&block)
if Rails::VERSION::MAJOR >= 6 || Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2
ActiveSupport.on_load(:action_controller_test_case, run_once: true, &block)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice run_once: true on load tag

if Rails::VERSION::MAJOR >= 6 || Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2
ActiveSupport.on_load(:action_controller_test_case, run_once: true, &block)
else
ActionController::TestCase.instance_eval(&block)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice checking version support for the on load hook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants