From a213ac360f104d7ba6e9395cd9fdcb8e212a054e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 18 May 2018 13:35:09 -0400 Subject: [PATCH] Raise a better exception when a invalid depreation behavior is set Fixes #32928. --- activesupport/lib/active_support/deprecation/behaviors.rb | 4 ++++ activesupport/test/deprecation_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index 66d6f3225a..3abd25aa85 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -94,6 +94,10 @@ def behavior=(behavior) private def arity_coerce(behavior) + unless behavior.respond_to?(:call) + raise ArgumentError, "#{behavior.inspect} is not a valid deprecation behavior." + end + if behavior.arity == 4 || behavior.arity == -1 behavior else diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index 60673c032b..105153584d 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -182,6 +182,14 @@ def test_default_notify_behavior end end + def test_default_invalid_behavior + e = assert_raises(ArgumentError) do + ActiveSupport::Deprecation.behavior = :invalid + end + + assert_equal ":invalid is not a valid deprecation behavior.", e.message + end + def test_deprecated_instance_variable_proxy assert_not_deprecated { @dtc.request.size } -- GitLab