aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2018-05-18 13:35:09 -0400
committerRafael Mendonça França <rafaelmfranca@gmail.com>2018-05-18 13:35:09 -0400
commita213ac360f104d7ba6e9395cd9fdcb8e212a054e (patch)
tree55cbd1753aee6a498d25eebb2b0fdf90d8a20548
parent9f95767979579f5761cb0d2bcccb67f3662349c5 (diff)
downloadrails-a213ac360f104d7ba6e9395cd9fdcb8e212a054e.tar.gz
rails-a213ac360f104d7ba6e9395cd9fdcb8e212a054e.tar.bz2
rails-a213ac360f104d7ba6e9395cd9fdcb8e212a054e.zip
Raise a better exception when a invalid depreation behavior is set
Fixes #32928.
-rw-r--r--activesupport/lib/active_support/deprecation/behaviors.rb4
-rw-r--r--activesupport/test/deprecation_test.rb8
2 files changed, 12 insertions, 0 deletions
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 @@ module ActiveSupport
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 @@ class DeprecationTest < ActiveSupport::TestCase
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 }