Skip to content

Commit

Permalink
Use ActiveRecord.deprecator when available (#437)
Browse files Browse the repository at this point in the history
Rails 7.1 will deprecate using the singleton ActiveSupport::Deprecation
instance. This directly uses the one from ActiveRecord.

Co-authored-by: Josh Branham <[email protected]>
  • Loading branch information
etiennebarrie and joshbranham authored Apr 29, 2023
1 parent 799d60b commit dee8d41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions test/legacy_active_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ class LegacyPerson < ActiveRecord::Base
attr_encrypted :email, :key => 'a secret key'
attr_encrypted :credentials, :key => Proc.new { |user| Encryptor.encrypt(:value => user.salt, :key => 'some private key', insecure_mode: true, algorithm: 'aes-256-cbc') }, :marshal => true

ActiveSupport::Deprecation.silenced = true
def after_initialize; end
ActiveSupport::Deprecation.silenced = false
if ActiveRecord.respond_to?(:deprecator)
ActiveRecord.deprecator.silence do
def after_initialize; end
end
else
ActiveSupport::Deprecation.silenced = true
def after_initialize; end
ActiveSupport::Deprecation.silenced = false
end

after_initialize :initialize_salt_and_credentials

Expand Down
6 changes: 5 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
require 'active_record'
require 'digest/sha2'
require 'sequel'
ActiveSupport::Deprecation.behavior = :raise
if ActiveRecord.respond_to?(:deprecator)
ActiveRecord.deprecator.behavior = :raise
else
ActiveSupport::Deprecation.behavior = :raise
end

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$:.unshift(File.dirname(__FILE__))
Expand Down

0 comments on commit dee8d41

Please sign in to comment.