mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Only convert direct hash instances in hash with indifferent access.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user