aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-07-31 12:38:29 +0200
committerYves Senn <yves.senn@gmail.com>2014-07-31 12:38:29 +0200
commit7dd452cc892c402a944d5a22f83c74a49a054baa (patch)
treec052f3fcf1039c96105308bdf3b92d6ce77d723c
parent316b32d19c5b31feef53f4cc772870e81a5a909d (diff)
parent787d5b13426c180b4b7e8a9a72a0ce0dc85f3ee0 (diff)
downloadrails-7dd452cc892c402a944d5a22f83c74a49a054baa.tar.gz
rails-7dd452cc892c402a944d5a22f83c74a49a054baa.tar.bz2
rails-7dd452cc892c402a944d5a22f83c74a49a054baa.zip
Merge pull request #16356 from gchan/add-hwia-tests
Add tests to ensure default proc is used when `HashWithIndifferentAccess' is initialized with a block
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index dbbb2d77da..5e9fdfd872 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -586,6 +586,8 @@ class HashExtTest < ActiveSupport::TestCase
roundtrip = mixed_with_default.with_indifferent_access.to_hash
assert_equal @strings, roundtrip
assert_equal '1234', roundtrip.default
+
+ # Ensure nested hashes are not HashWithIndiffereneAccess
new_to_hash = @nested_mixed.with_indifferent_access.to_hash
assert_not new_to_hash.instance_of?(HashWithIndifferentAccess)
assert_not new_to_hash["a"].instance_of?(HashWithIndifferentAccess)
@@ -1516,6 +1518,16 @@ class HashToXmlTest < ActiveSupport::TestCase
assert_equal expected, Hash.from_trusted_xml('<product><name type="yaml">:value</name></product>')
end
+ def test_should_use_default_proc_for_unknown_key
+ hash_wia = HashWithIndifferentAccess.new { 1 + 2 }
+ assert_equal 3, hash_wia[:new_key]
+ end
+
+ def test_should_use_default_proc_if_no_key_is_supplied
+ hash_wia = HashWithIndifferentAccess.new { 1 + 2 }
+ assert_equal 3, hash_wia.default
+ end
+
def test_should_use_default_value_for_unknown_key
hash_wia = HashWithIndifferentAccess.new(3)
assert_equal 3, hash_wia[:new_key]