From 839fee9418e1700ce70ba7880021b104400253c8 Mon Sep 17 00:00:00 2001 From: Sarah Chen Date: Thu, 14 Nov 2024 16:02:59 -0500 Subject: [PATCH] Fix deprecation behavior --- .../contrib/rails/support/deprecation.rb | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/spec/datadog/tracing/contrib/rails/support/deprecation.rb b/spec/datadog/tracing/contrib/rails/support/deprecation.rb index 5724fa9a582..c99c4676823 100644 --- a/spec/datadog/tracing/contrib/rails/support/deprecation.rb +++ b/spec/datadog/tracing/contrib/rails/support/deprecation.rb @@ -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