Raise a better exception when a invalid depreation behavior is set

Fixes #32928.
This commit is contained in:
Rafael Mendonça França 2018-05-18 13:35:09 -04:00
parent 9f95767979
commit a213ac360f
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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 }