aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-05-15 08:31:15 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-05-15 08:31:15 -0700
commite84207b3373bfb0ab7fbce1fd807e26451442cff (patch)
tree0862a958d9dab198e4ba7f5a919d9ff35c425405
parent5db56659f3145400fdfcde62e94394941a0a3d5e (diff)
parentf9c82f586cd73d9124d0fd89f9070e640a49adac (diff)
downloadrails-e84207b3373bfb0ab7fbce1fd807e26451442cff.tar.gz
rails-e84207b3373bfb0ab7fbce1fd807e26451442cff.tar.bz2
rails-e84207b3373bfb0ab7fbce1fd807e26451442cff.zip
Merge pull request #10631 from kennyj/improve_10266
Fix HWIA#to_hash behavior with array of hashes.
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb4
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb5
2 files changed, 7 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb
index 9a9ed02bd9..bdb8877f55 100644
--- a/activesupport/lib/active_support/hash_with_indifferent_access.rb
+++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -231,7 +231,7 @@ module ActiveSupport
def to_hash
_new_hash= {}
each do |key, value|
- _new_hash[convert_key(key)] = convert_value(value,true)
+ _new_hash[convert_key(key)] = convert_value(value, true)
end
Hash.new(default).merge!(_new_hash)
end
@@ -246,7 +246,7 @@ module ActiveSupport
_convert_for_to_hash ? value.to_hash : value.nested_under_indifferent_access
elsif value.is_a?(Array)
value = value.dup if value.frozen?
- value.map! { |e| convert_value(e) }
+ value.map! { |e| convert_value(e, _convert_for_to_hash) }
else
value
end
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index b385e806bc..dfcc6cd12a 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -506,6 +506,11 @@ class HashExtTest < ActiveSupport::TestCase
def test_indifferent_hash_with_array_of_hashes
hash = { "urls" => { "url" => [ { "address" => "1" }, { "address" => "2" } ] }}.with_indifferent_access
assert_equal "1", hash[:urls][:url].first[:address]
+
+ hash = hash.to_hash
+ assert_not hash.instance_of?(HashWithIndifferentAccess)
+ assert_not hash["urls"].instance_of?(HashWithIndifferentAccess)
+ assert_not hash["urls"]["url"].first.instance_of?(HashWithIndifferentAccess)
end
def test_should_preserve_array_subclass_when_value_is_array