diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index feb15085863fe7aee0b95f5bad99ccdc67cb96ec..f0842f201d6d89135f7819dbd930b5fa667f88e6 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -1,4 +1,5 @@ require "active_support/notifications" +require "active_support/core_ext/array/wrap" module ActiveSupport module Deprecation @@ -11,7 +12,7 @@ def behavior end def behavior=(behavior) - @behavior = DEFAULT_BEHAVIORS[behavior] || behavior + @behavior = Array.wrap(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b } end end diff --git a/activesupport/lib/active_support/deprecation/reporting.rb b/activesupport/lib/active_support/deprecation/reporting.rb index 03c445ffbf80d6c73183f6e2027d4e636ff6c0db..49d58cd3a1231c5c344edfc8c1c707d4c3d9229b 100644 --- a/activesupport/lib/active_support/deprecation/reporting.rb +++ b/activesupport/lib/active_support/deprecation/reporting.rb @@ -4,8 +4,9 @@ class << self attr_accessor :silenced def warn(message = nil, callstack = caller) - if behavior && !silenced - behavior.call(deprecation_message(callstack, message), callstack) + return if silenced + deprecation_message(callstack, message).tap do |m| + behavior.each { |b| b.call(m, callstack) } end end diff --git a/activesupport/lib/active_support/i18n_railtie.rb b/activesupport/lib/active_support/i18n_railtie.rb index d82e54f1d40ddfc20c9850028de7eb712045e6dc..db09919fd3ee3a1c9911f8cbeb51054de95b96ff 100644 --- a/activesupport/lib/active_support/i18n_railtie.rb +++ b/activesupport/lib/active_support/i18n_railtie.rb @@ -1,6 +1,7 @@ require "active_support" require "rails" require "active_support/file_update_checker" +require "active_support/core_ext/array/wrap" module I18n class Railtie < Rails::Railtie diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index cf27357b321eba1ffe4e061fd5e7c2fe75cdad2b..44f1aebb37f863865cb4a9f6832253ffff9a98a9 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -80,6 +80,19 @@ def test_nil_behavior_is_ignored assert_deprecated(/foo=nil/) { @dtc.partially } end + def test_several_behaviors + @a, @b = nil, nil + + ActiveSupport::Deprecation.behavior = [ + Proc.new { |msg, callstack| @a = msg }, + Proc.new { |msg, callstack| @b = msg } + ] + + @dtc.partially + assert_match(/foo=nil/, @a) + assert_match(/foo=nil/, @b) + end + def test_deprecated_instance_variable_proxy assert_not_deprecated { @dtc.request.size }