Skip to content

Commit

Permalink
Add ActiveRecord 7.1 to appraisal and fix deprecation warning (#425)
Browse files Browse the repository at this point in the history
Set the deprecation behavior on ActiveRecord.deprecator, instead of
ActiveSupport::Deprecation, as that is deprecated.
Fixes the following warnings:

      ActiveSupport::DeprecationException: DEPRECATION WARNING: Calling
      behavior= on ActiveSupport::Deprecation is deprecated and will be
      removed from Rails (use Rails.application.deprecators.behavior=
      instead)
  • Loading branch information
p8 authored Dec 13, 2023
1 parent b955dc8 commit eef7603
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ end
appraise "rails-7-0" do
gem "activerecord", "~> 7.0.0"
end

appraise "rails-7-1" do
gem "activerecord", "~> 7.1.0"
end
14 changes: 11 additions & 3 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def assert_equal_or_nil(a, b)
end

def assert_no_deprecation_warning_raised_by(failure_message = 'ActiveRecord deprecation warning raised when we didn\'t expect it', pass_message = 'No ActiveRecord deprecation raised')
original_behavior = ActiveSupport::Deprecation.behavior
ActiveSupport::Deprecation.behavior = :raise
original_behavior = active_record_deprecator.behavior
active_record_deprecator.behavior = :raise
begin
yield
rescue ActiveSupport::DeprecationException => e
Expand All @@ -65,5 +65,13 @@ def assert_no_deprecation_warning_raised_by(failure_message = 'ActiveRecord depr
pass pass_message
end
ensure
ActiveSupport::Deprecation.behavior = original_behavior
active_record_deprecator.behavior = original_behavior
end

def active_record_deprecator
if ActiveRecord::VERSION::MAJOR == 7 && ActiveRecord::VERSION::MINOR >= 1 || ActiveRecord::VERSION::MAJOR > 7
ActiveRecord.deprecator
else
ActiveSupport::Deprecation
end
end

0 comments on commit eef7603

Please sign in to comment.