diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index 87251388563e9..3c8a59f00a754 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -43,8 +43,8 @@ def symbolize_keys! alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! - def assert_valid_keys(valid_keys) - unknown_keys = keys - valid_keys + def assert_valid_keys(*valid_keys) + unknown_keys = keys - [valid_keys].flatten raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty? end end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 8addd895ccddd..f42b6fde2f12c 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -96,10 +96,12 @@ def test_indifferent_writing def test_assert_valid_keys assert_nothing_raised do { :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) + { :failure => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny) end assert_raises(ArgumentError, "Unknown key(s): failore") do { :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) + { :failore => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny) end end