aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/hash_ext_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-06-03 16:46:59 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-06-03 16:46:59 -0700
commit424fa92b35231a4217574e8012d96a0954659cde (patch)
treeb69c8b51c0497d45bd253bfe64f8a9edd1627276 /activesupport/test/core_ext/hash_ext_test.rb
parent438e2ad3613f7266cfec77247ecb9b4e7c629b94 (diff)
parentc44a929f49ac17709d9efce3951b0f540ecdf8f9 (diff)
downloadrails-424fa92b35231a4217574e8012d96a0954659cde.tar.gz
rails-424fa92b35231a4217574e8012d96a0954659cde.tar.bz2
rails-424fa92b35231a4217574e8012d96a0954659cde.zip
Merge pull request #10784 from senny/10526_prevent_key_transformation
Prevent side effects in `Hash#with_indifferent_access`.
Diffstat (limited to 'activesupport/test/core_ext/hash_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index dfcc6cd12a..39bd0a2dd4 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -503,6 +503,13 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal [1], hash[:a]
end
+ def test_with_indifferent_access_has_no_side_effects_on_existing_hash
+ hash = {content: [{:foo => :bar, 'bar' => 'baz'}]}
+ hash.with_indifferent_access
+
+ assert_equal [:foo, "bar"], hash[:content].first.keys
+ end
+
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]