diff options
author | Larry Sprock <larry@lucidbleu.com> | 2010-11-14 15:01:14 +0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-11-14 17:14:47 +0800 |
commit | f43e5d160bf9708ad50b58c8168e38579769e024 (patch) | |
tree | 6e62b75009fd7b8fc4eb6541005c7ce7cab2df10 /activesupport/test | |
parent | 293c8a4de5bfe3274e0fda7dfab1b6ec296bb829 (diff) | |
download | rails-f43e5d160bf9708ad50b58c8168e38579769e024.tar.gz rails-f43e5d160bf9708ad50b58c8168e38579769e024.tar.bz2 rails-f43e5d160bf9708ad50b58c8168e38579769e024.zip |
HashWithIndifferentAccess should not change the subclass of an array
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index d7b77e43bd..370f26b0d7 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -8,6 +8,9 @@ require 'active_support/core_ext/object/conversions' class HashExtTest < Test::Unit::TestCase class IndifferentHash < HashWithIndifferentAccess end + + class SubclassingArray < Array + end def setup @strings = { 'a' => 1, 'b' => 2 } @@ -251,6 +254,20 @@ class HashExtTest < Test::Unit::TestCase hash = { "urls" => { "url" => [ { "address" => "1" }, { "address" => "2" } ] }}.with_indifferent_access assert_equal "1", hash[:urls][:url].first[:address] end + + def test_should_preserve_array_subclass_when_value_is_array + array = SubclassingArray.new + array << { "address" => "1" } + hash = { "urls" => { "url" => array }}.with_indifferent_access + assert_equal SubclassingArray, hash[:urls][:url].class + end + + def test_should_preserve_array_class_when_hash_value_is_frozen_array + array = SubclassingArray.new + array << { "address" => "1" } + hash = { "urls" => { "url" => array.freeze }}.with_indifferent_access + assert_equal SubclassingArray, hash[:urls][:url].class + end def test_stringify_and_symbolize_keys_on_indifferent_preserves_hash h = HashWithIndifferentAccess.new |