aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-10-29 09:54:55 -0600
committerSean Griffin <sean@seantheprogrammer.com>2015-10-29 09:54:55 -0600
commitddb886ef1338e0e4fa84d6d8ba55161da34d91aa (patch)
tree7978a76a0c0db50f220402e05e9f799354068366 /activesupport/test/core_ext
parent90dbfdcba2110eb40f5c0c3a1d4c1d6ed46f5ab5 (diff)
parent6e574e8a11635ec4e579e5b247f6492b9bdc9279 (diff)
downloadrails-ddb886ef1338e0e4fa84d6d8ba55161da34d91aa.tar.gz
rails-ddb886ef1338e0e4fa84d6d8ba55161da34d91aa.tar.bz2
rails-ddb886ef1338e0e4fa84d6d8ba55161da34d91aa.zip
Merge pull request #16357 from gchan/hwia-respects-to-hash-default
`HashWithIndifferentAccess.new` respects the default value or proc on objects that respond to `#to_hash`
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 4624338df1..1d9b56b1b4 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -1044,6 +1044,24 @@ class HashExtTest < ActiveSupport::TestCase
assert_nothing_raised { HashWithIndifferentAccess.new_from_hash_copying_default(hash) }
end
+
+ def test_new_with_to_hash_conversion_copies_default
+ normal_hash = Hash.new(3)
+ normal_hash[:a] = 1
+
+ hash = HashWithIndifferentAccess.new(HashByConversion.new(normal_hash))
+ assert_equal 1, hash[:a]
+ assert_equal 3, hash[:b]
+ end
+
+ def test_new_with_to_hash_conversion_copies_default_proc
+ normal_hash = Hash.new { 1 + 2 }
+ normal_hash[:a] = 1
+
+ hash = HashWithIndifferentAccess.new(HashByConversion.new(normal_hash))
+ assert_equal 1, hash[:a]
+ assert_equal 3, hash[:b]
+ end
end
class IWriteMyOwnXML