From c9d48c508eca267d083bfa06094975a1666c4fc7 Mon Sep 17 00:00:00 2001 From: Dzmitry Date: Sat, 8 Aug 2020 22:21:04 +0300 Subject: [PATCH 1/2] Call sorcery config block where it is defined [#227] Before this commit sorcery config block was saved into a variable and called after including `Sorcery::Controller` into `ActionController::Base` (in the included block). In #209 the initialization code was changed to include `Sorcery::Controller` into `ActionController::Base` after loading action controller (in the onload block) to fix deprecation warning related to autoloading. After this change calling the user model in the rails development console started to fail with "To use reset_password submodule, you must define a mailer" error (#227), because sorcery config block was not called (calling the user model doesn't load action controller) and `::Sorcery::Controller::Config.user_config` was nil Because of this issue changes in #209 have been reverted (#234) There is no need to delay calling sorcery config block until `Sorcery::Controller` is included into `ActionController::Base` This commit changes the code to call sorcery config where it is defined. It will allow to apply changes in #209 to fix deprecation warning from autoloading --- lib/sorcery/controller.rb | 2 -- lib/sorcery/controller/config.rb | 7 ++----- spec/controllers/controller_activity_logging_spec.rb | 2 ++ 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/sorcery/controller.rb b/lib/sorcery/controller.rb index ba4a69fd..ca0ca845 100644 --- a/lib/sorcery/controller.rb +++ b/lib/sorcery/controller.rb @@ -14,8 +14,6 @@ def self.included(klass) # rubocop:enable Lint/HandleExceptions end end - Config.update! - Config.configure! end module InstanceMethods diff --git a/lib/sorcery/controller/config.rb b/lib/sorcery/controller/config.rb index 1a9bf112..ee791d1a 100644 --- a/lib/sorcery/controller/config.rb +++ b/lib/sorcery/controller/config.rb @@ -54,11 +54,8 @@ def user_config(&blk) end def configure(&blk) - @configure_blk = blk - end - - def configure! - @configure_blk.call(self) if @configure_blk + update! + blk.call(self) if blk end end diff --git a/spec/controllers/controller_activity_logging_spec.rb b/spec/controllers/controller_activity_logging_spec.rb index bee7cae1..60c76ffc 100644 --- a/spec/controllers/controller_activity_logging_spec.rb +++ b/spec/controllers/controller_activity_logging_spec.rb @@ -45,6 +45,8 @@ login_user(user) now = Time.now.in_time_zone Timecop.freeze(now) + + sorcery_controller_property_set(:register_logout_time, true) expect(user).to receive(:set_last_logout_at).with(be_within(0.1).of(now)) logout_user From 6fa3214c090a68ea477c0adc8143876eb1f4e5ab Mon Sep 17 00:00:00 2001 From: Dzmitry Date: Mon, 10 Aug 2020 17:53:12 +0300 Subject: [PATCH 2/2] Add back changes that fix deprecation warning related to autoloading in Rails 6 [#209] Deprecation warning "Initialization autoloaded the constants ActionText::ContentHelper and ActionText::TagHelper." has been fixed in #209, but then reverted because of "To use reset_password submodule, you must define a mailer" error occurring when calling the user model in the rails development console (#227) c9d48c50 allows to add back changes from #209 that fix the warning without breaking the user model in the rails development console --- lib/sorcery/engine.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/sorcery/engine.rb b/lib/sorcery/engine.rb index eb5de9b3..faa7a809 100644 --- a/lib/sorcery/engine.rb +++ b/lib/sorcery/engine.rb @@ -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) ActionController::Base.helper_method :current_user ActionController::Base.helper_method :logged_in? end