mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Only convert direct hash instances in hash with indifferent access.
This commit is contained in:
parent
9332cc582e
commit
ce9456eca0
2 changed files with 11 additions and 4 deletions
|
@ -140,11 +140,10 @@ module ActiveSupport
|
|||
end
|
||||
|
||||
def convert_value(value)
|
||||
case value
|
||||
when Hash
|
||||
if value.class == Hash
|
||||
self.class.new_from_hash_copying_default(value)
|
||||
when Array
|
||||
value.dup.replace(value.collect { |e| e.is_a?(Hash) ? self.class.new_from_hash_copying_default(e) : e })
|
||||
elsif value.is_a?(Array)
|
||||
value.dup.replace(value.map { |e| convert_value(e) })
|
||||
else
|
||||
value
|
||||
end
|
||||
|
|
|
@ -12,6 +12,9 @@ class HashExtTest < Test::Unit::TestCase
|
|||
class SubclassingArray < Array
|
||||
end
|
||||
|
||||
class SubclassingHash < Hash
|
||||
end
|
||||
|
||||
def setup
|
||||
@strings = { 'a' => 1, 'b' => 2 }
|
||||
@symbols = { :a => 1, :b => 2 }
|
||||
|
@ -105,6 +108,11 @@ class HashExtTest < Test::Unit::TestCase
|
|||
assert_equal @strings, @mixed.with_indifferent_access.dup.stringify_keys!
|
||||
end
|
||||
|
||||
def test_hash_subclass
|
||||
flash = { "foo" => SubclassingHash.new.tap { |h| h["bar"] = "baz" } }.with_indifferent_access
|
||||
assert_kind_of SubclassingHash, flash["foo"]
|
||||
end
|
||||
|
||||
def test_indifferent_assorted
|
||||
@strings = @strings.with_indifferent_access
|
||||
@symbols = @symbols.with_indifferent_access
|
||||
|
|
Loading…
Reference in a new issue