Skip to content

Commit

Permalink
Make assert_valid_keys slightly more lenient
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2166 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Sep 9, 2005
1 parent 7dbf051 commit 5583315
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/core_ext/hash/keys.rb
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions activesupport/test/core_ext/hash_ext_test.rb
Expand Up @@ -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

Expand Down

0 comments on commit 5583315

Please sign in to comment.