Remove deprecation warning using controller filters inside initializer#7340
Conversation
|
I can't find a good way to write a test for this. The issue is at boot time, calling The initializers run very early on test setup, even on feature tests. I tried to write a feature test that restart/reload the server but couldn't make it. I test this PR manually on each rails version by adding: |
|
Hi, I can see that all Rails 6.1 builds are failing. Errors seem related to this change:
https://github.com/activeadmin/activeadmin/runs/5233438250?check_suite_focus=true#step:9:87 |
|
I'm guessing this change is correct (passes realworld cucumber features), but the unit tests are broken by it. If that's the culprit, we need to adapt unit tests. |
|
Hi, I believe the failures are related to test execution order. I'm going to check to confirm and see how to fix it. |
88b14b0 to
7b19147
Compare
|
@tagliala, @deivid-rodriguez it was a flaky test. I'm running defined hooks on any class that includes The alternative is to move this https://github.com/activeadmin/activeadmin/pull/7340/files#diff-f0cf2650684e208d1c3f6a07e874099749954701701a0212c6bce155685606f8R34-R35 from the module into each defined class (ActiveAdmin::Devise::SessionControler, ActiveAdmin::Devise::RegistrationController, etc). |
7d24902 to
af076e0
Compare
|
Ended up using the alternative to prevent problems when |
javierjulio
left a comment
There was a problem hiding this comment.
@mgrunberg this is not an area I really know anything about so hoping the others can help. Thank you!
deivid-rodriguez
left a comment
There was a problem hiding this comment.
This looks good to me! Can you rebase and squash to a single commit?
Defining Action filters (`before_action`, `skip_before_action`, etc) using `ActiveAdmin.before_action` on the initializer file produces the following warning. ``` DEPRECATION WARNING: Initialization autoloaded the constants ApplicationHelper, TimeHelper, DeviseHelper, ApplicationController, InheritedResources::Base, DeviseController, Devise::SessionsController, Devise::PasswordsController, Devise::UnlocksController, Devise::RegistrationsController, and Devise::ConfirmationsController. Being able to do this is deprecated. Autoloading during initialization is going to be an error condition in future versions of Rails. ``` NOTE: On Rails 7.0 it produces the following error. ``` lib/active_admin/base_controller/authorization.rb:3:in `<module:ActiveAdmin>': uninitialized constant InheritedResources::Base (NameError) Did you mean? Base64 ``` ActiveAdmin module forwards the filter call to all controllers. That mean that we are using classes meant to be autoloaded inside the initializer. That's not allowed in Rails 7.x (see the second red box of https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#config-autoload-paths). This commit defer the forward until controllers are loaded by using ActiveSupport.on_load hook. NOTE: I'm adding `ActiveSupport.run_load_hooks(:active_admin_controller, self)` on each devise controller to preserve original behaviour. Adding that to `ActiveAdmin::Devise::Controller` leads to flaky tests depending on what run first: `spec/unit/devise_spec.rb` or `spec/unit/application_spec.rb`.
969d023 to
3d753d2
Compare
|
@deivid-rodriguez done |
|
Awesome thanks so much! |
|
This actually closes #5772, right? |
Yes, that correct |
Defining Action filters (
before_action,skip_before_action, etc) usingActiveAdmin.before_actionon the initializer file produces the following warning.NOTE: On Rails 7.0 it produces the following error.
ActiveAdmin module forwards the filter call to all controllers. That means that we are using classes meant to be autoloaded inside the initializer. That's the source of the warning and it's not allowed starging Rails 7.x (see the second red box of https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#config-autoload-paths).
This PR defers the forward until controllers are loaded by using ActiveSupport.on_load hook.
Closes #5772.