aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-09 08:20:14 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-09 08:20:14 +0000
commit558331596fbf9139ef529b14d50c6e258e63fb67 (patch)
tree1728890354516066185d27610b556b46e876eb96 /activesupport
parent7dbf051e5442713a34fe28d6480615eb6dbdc5c2 (diff)
downloadrails-558331596fbf9139ef529b14d50c6e258e63fb67.tar.gz
rails-558331596fbf9139ef529b14d50c6e258e63fb67.tar.bz2
rails-558331596fbf9139ef529b14d50c6e258e63fb67.zip
Make assert_valid_keys slightly more lenient
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2166 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/keys.rb4
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb2
2 files changed, 4 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb
index 8725138856..3c8a59f00a 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 @@ module ActiveSupport #:nodoc:
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 8addd895cc..f42b6fde2f 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -96,10 +96,12 @@ class HashExtTest < Test::Unit::TestCase
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