Skip to content

Commit

Permalink
Fix deprecation behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahchen6 committed Nov 14, 2024
1 parent 5fe0a08 commit 839fee9
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions spec/datadog/tracing/contrib/rails/support/deprecation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,27 @@ def raise_on_rails_deprecation!
# of which warnings are allowed, in case we need
# such feature.
#
# In Rails 7.1 calling ActiveSupport::Deprecation.behavior= is deprecated
if defined?(Rails) && Rails.gem_version >= Gem::Version.new(7.1)
# In Rails 7.1 calling ActiveSupport::Deprecation.behavior= raises an exception.
# The new way of configuring deprecation is per framework, and each framework has
# its own deprecator object. If none of the frameworks have a deprecator object,
# we must be on an older version of Rails, in which case we can configure the
# deprecation behavior on ActiveSupport globally.
executed = false
if defined?(ActiveRecord) && ActiveRecord.respond_to?(:deprecator)
ActiveRecord.deprecator.behavior = :raise
executed = true
end
if defined?(ActiveModel) && ActiveModel.respond_to?(:deprecator)
ActiveModel.deprecator.behavior = :raise
executed = true
end
if defined?(ActionCable) && ActionCable.respond_to?(:deprecator)
ActionCable.deprecator.behavior = :raise
executed = true
end
if defined?(Rails) && Rails.respond_to?(:deprecator)
Rails.deprecator.behavior = :raise
else
ActiveSupport::Deprecation.behavior = :raise
executed = true
end
ActiveSupport::Deprecation.behavior = :raise if !executed
end

0 comments on commit 839fee9

Please sign in to comment.