aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-16 13:27:59 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-16 13:27:59 -0300
commitd8569bd49887f045ec949aa85a1e78f5438e9b88 (patch)
tree73b3c9860225aaa2554b2a0f930b816952d6c05c /activesupport
parent4dc6b64c542f82270958976335e468d70246265c (diff)
parentfedb16ae12e60de95e4b1177a131e896da3a8012 (diff)
downloadrails-d8569bd49887f045ec949aa85a1e78f5438e9b88.tar.gz
rails-d8569bd49887f045ec949aa85a1e78f5438e9b88.tar.bz2
rails-d8569bd49887f045ec949aa85a1e78f5438e9b88.zip
Merge pull request #15684 from aditya-kapoor/add-tests-for-assert-valid-keys
Add test cases for Hash#asset_valid_keys
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index f18172a5ce..eb8e87cc31 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -691,6 +691,11 @@ class HashExtTest < ActiveSupport::TestCase
{ :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])
{ :failure => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny)
end
+ # not all valid keys are required to be present
+ assert_nothing_raised do
+ { :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny, :sunny ])
+ { :failure => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny, :sunny)
+ end
exception = assert_raise ArgumentError do
{ :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])
@@ -701,6 +706,16 @@ class HashExtTest < ActiveSupport::TestCase
{ :failore => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny)
end
assert_equal "Unknown key: :failore. Valid keys are: :failure, :funny", exception.message
+
+ exception = assert_raise ArgumentError do
+ { :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure ])
+ end
+ assert_equal "Unknown key: :failore. Valid keys are: :failure", exception.message
+
+ exception = assert_raise ArgumentError do
+ { :failore => "stuff", :funny => "business" }.assert_valid_keys(:failure)
+ end
+ assert_equal "Unknown key: :failore. Valid keys are: :failure", exception.message
end
def test_assorted_keys_not_stringified