-
Notifications
You must be signed in to change notification settings - Fork 228
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
Add back changes that fix deprecation warning related to autoloading in Rails 6 #255
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,18 +9,12 @@ class Engine < Rails::Engine | |
|
||
# TODO: Should this include a modified version of the helper methods? | ||
initializer 'extend Controller with sorcery' do | ||
# FIXME: on_load is needed to fix Rails 6 deprecations, but it breaks | ||
# applications due to undefined method errors. | ||
# ActiveSupport.on_load(:action_controller_api) do | ||
if defined?(ActionController::API) | ||
ActionController::API.send(:include, Sorcery::Controller) | ||
ActiveSupport.on_load(:action_controller_api) do | ||
ActionController::API.include(Sorcery::Controller) | ||
end | ||
|
||
# FIXME: on_load is needed to fix Rails 6 deprecations, but it breaks | ||
# applications due to undefined method errors. | ||
# ActiveSupport.on_load(:action_controller_base) do | ||
if defined?(ActionController::Base) | ||
ActionController::Base.send(:include, Sorcery::Controller) | ||
ActiveSupport.on_load(:action_controller_base) do | ||
ActionController::Base.include(Sorcery::Controller) | ||
Comment on lines
+12
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This solution is confirmed as breaking for existing applications, although an alternative that does work is on the v1 rework. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean #227 there? Or does this change cause other issues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per FIXME, changing to on_load causes existing applications to generate undefined method errors. This has been pretty consistent every time we've tried switching. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any other Sorcery/sorcery issues related to switching to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #132 is related There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The rework ( Honestly, it would probably make sense for you to create a temporary fork with your changes here and use that until v1 is released. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, got it. Thank you for the advice @athix |
||
ActionController::Base.helper_method :current_user | ||
ActionController::Base.helper_method :logged_in? | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With how the config works in v1, I don't know that immediately calling the block makes sense.
configure
essentially sets the global config, which gets executed on duplicates rather than the primary instance. I'll definitely keep this in mind though, and see if it can be simplified to a single method when testing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While inspecting the code I found out that
Sorcery::Controller::Config
class (not instance) is intended to be used in controllers and it is not relevant where we set class variables (in theconfigure!
method after action controller is laded or in the sorcery initializer when callingconfigure
with a block)Instances of
Sorcery::Model::Config
are configured in::Sorcery::Controller::Config.user_config
block and used in user modelsThere is another way to fix #227: move configure user block out of the configure controller block. Sorcery initializer will look like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely like calling
Sorcery.configure
overRails.application.config.sorcery.configure
, I'll see about implementing that for sure.I've reworked how the config works quite a bit in the rework, but if there ends up still being a
configure_user
block, I'll extract it out like you've suggested. I like that separation better.