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

Use a dedicated ActiveSupport::Deprecation #5583

Merged
merged 2 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/devise_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module DeviseHelper
# Retain this method for backwards compatibility, deprecated in favor of modifying the
# devise/shared/error_messages partial.
def devise_error_messages!
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
Devise.deprecator.warn <<-DEPRECATION.strip_heredoc
[Devise] `DeviseHelper#devise_error_messages!` is deprecated and will be
removed in the next major version.

Expand Down
6 changes: 5 additions & 1 deletion lib/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,12 @@ def self.secure_compare(a, b)
res == 0
end

def self.deprecator
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to register the deprecator in the application deprecator. We want users to be able to silence the deprecations in their apps, or change the behavior to use notifications for example. Can you do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@deprecator ||= ActiveSupport::Deprecation.new("5.0", "Devise")
end

def self.activerecord51? # :nodoc:
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
deprecator.warn <<-DEPRECATION.strip_heredoc
[Devise] `Devise.activerecord51?` is deprecated and will be removed in the next major version.
It is a non-public method that's no longer used internally, but that other libraries have been relying on.
DEPRECATION
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/controllers/sign_in_out.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def sign_in(resource_or_scope, *args)
expire_data_after_sign_in!

if options[:bypass]
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
Devise.deprecator.warn(<<-DEPRECATION.strip_heredoc, caller)
[Devise] bypass option is deprecated and it will be removed in future version of Devise.
Please use bypass_sign_in method instead.
Example:
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/models/authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module Authenticatable
:remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at]

include Devise::DeprecatedConstantAccessor
deprecate_constant "BLACKLIST_FOR_SERIALIZATION", "Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION"
deprecate_constant "BLACKLIST_FOR_SERIALIZATION", "Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION", deprecator: Devise.deprecator

included do
class_attribute :devise_modules, instance_writer: false
Expand Down
4 changes: 2 additions & 2 deletions lib/devise/models/database_authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def clean_up_passwords
# is also rejected as long as it is also blank.
def update_with_password(params, *options)
if options.present?
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
Devise.deprecator.warn <<-DEPRECATION.strip_heredoc
[Devise] The second argument of `DatabaseAuthenticatable#update_with_password`
(`options`) is deprecated and it will be removed in the next major version.
It was added to support a feature deprecated in Rails 4, so you can safely remove it
Expand Down Expand Up @@ -128,7 +128,7 @@ def update_with_password(params, *options)
#
def update_without_password(params, *options)
if options.present?
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
Devise.deprecator.warn <<-DEPRECATION.strip_heredoc
[Devise] The second argument of `DatabaseAuthenticatable#update_without_password`
(`options`) is deprecated and it will be removed in the next major version.
It was added to support a feature deprecated in Rails 4, so you can safely remove it
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/test/controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def sign_in(resource, deprecated = nil, scope: nil)
scope = resource
resource = deprecated

ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
Devise.deprecator.warn <<-DEPRECATION.strip_heredoc
[Devise] sign_in(:#{scope}, resource) on controller tests is deprecated and will be removed from Devise.
Please use sign_in(resource, scope: :#{scope}) instead.
DEPRECATION
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Devise
module TestHelpers
def self.included(base)
base.class_eval do
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
Devise.deprecator.warn <<-DEPRECATION.strip_heredoc
[Devise] including `Devise::TestHelpers` is deprecated and will be removed from Devise.
For controller tests, please include `Devise::Test::ControllerHelpers` instead.
DEPRECATION
Expand Down
4 changes: 3 additions & 1 deletion test/devise_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class DeviseTest < ActiveSupport::TestCase
end

test 'Devise.activerecord51? deprecation' do
assert_deprecated { Devise.activerecord51? }
assert_deprecated("`Devise.activerecord51?` is deprecated", Devise.deprecator) do
Devise.activerecord51?
end
end
end
4 changes: 3 additions & 1 deletion test/models/serializable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class SerializableTest < ActiveSupport::TestCase
end

test 'constant `BLACKLIST_FOR_SERIALIZATION` is deprecated' do
assert_deprecated { Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION }
assert_deprecated("Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION", Devise.deprecator) do
Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION
end
end

def assert_key(key, subject)
Expand Down
13 changes: 13 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
if ActiveSupport.respond_to?(:test_order)
ActiveSupport.test_order = :random
end
class ActiveSupport::TestCase
if ActiveSupport.version < Gem::Version.new("5.0")
def assert_deprecated(match, deprecator)
super(match) do
behavior = deprecator.behavior
deprecator.behavior = ActiveSupport::Deprecation.behavior
yield
ensure
deprecator.behavior = behavior
end
end
end
end

OmniAuth.config.logger = Logger.new('/dev/null')

Expand Down