mirror of https://github.com/rails/rails
parent
5f25435bf4
commit
c17c262cfc
|
@ -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.
|
* Add `String#truncate_words` to truncate a string by a number of words.
|
||||||
|
|
||||||
*Mohamed Osama*
|
*Mohamed Osama*
|
||||||
|
|
|
@ -75,6 +75,7 @@ module ActiveSupport
|
||||||
hash = hash.to_hash
|
hash = hash.to_hash
|
||||||
new(hash).tap do |new_hash|
|
new(hash).tap do |new_hash|
|
||||||
new_hash.default = hash.default
|
new_hash.default = hash.default
|
||||||
|
new_hash.default_proc = hash.default_proc if hash.default_proc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1543,6 +1543,17 @@ class HashToXmlTest < ActiveSupport::TestCase
|
||||||
assert_equal 3, hash_wia.default
|
assert_equal 3, hash_wia.default
|
||||||
end
|
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
|
# The XML builder seems to fail miserably when trying to tag something
|
||||||
# with the same name as a Kernel method (throw, test, loop, select ...)
|
# with the same name as a Kernel method (throw, test, loop, select ...)
|
||||||
def test_kernel_method_names_to_xml
|
def test_kernel_method_names_to_xml
|
||||||
|
|
Loading…
Reference in New Issue