From f43e5d160bf9708ad50b58c8168e38579769e024 Mon Sep 17 00:00:00 2001 From: Larry Sprock Date: Sun, 14 Nov 2010 15:01:14 +0800 Subject: HashWithIndifferentAccess should not change the subclass of an array --- activesupport/test/core_ext/hash_ext_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activesupport/test/core_ext/hash_ext_test.rb') 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 -- cgit v1.2.3