Make HWIA copy the default proc too.

[fixes #16279]
This commit is contained in:
Arthur Neves 2014-07-24 11:48:24 -04:00
parent 5f25435bf4
commit c17c262cfc
No known key found for this signature in database
GPG Key ID: 04A390FB1E433E17
3 changed files with 16 additions and 0 deletions

View File

@ -1,3 +1,7 @@
* Make `Hash#with_indifferent_access` copy the default proc too.
*arthurnn*, *Xanders*
* Add `String#truncate_words` to truncate a string by a number of words.
*Mohamed Osama*

View File

@ -75,6 +75,7 @@ module ActiveSupport
hash = hash.to_hash
new(hash).tap do |new_hash|
new_hash.default = hash.default
new_hash.default_proc = hash.default_proc if hash.default_proc
end
end

View File

@ -1543,6 +1543,17 @@ class HashToXmlTest < ActiveSupport::TestCase
assert_equal 3, hash_wia.default
end
def test_should_copy_the_default_proc_when_converting_to_hash_with_indifferent_access
hash = Hash.new do
2 + 1
end
assert_equal 3, hash[:foo]
hash_wia = hash.with_indifferent_access
assert_equal 3, hash_wia[:foo]
assert_equal 3, hash_wia[:bar]
end
# The XML builder seems to fail miserably when trying to tag something
# with the same name as a Kernel method (throw, test, loop, select ...)
def test_kernel_method_names_to_xml