1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed Hash#from_xml with keys that are all caps.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
This commit is contained in:
codebrulee 2009-05-04 12:36:22 -04:00 committed by Michael Koziarski
parent 8b6d2ef2f5
commit eb201e64c0
2 changed files with 17 additions and 1 deletions

View file

@ -217,7 +217,7 @@ class Hash
case params.class.to_s
when "Hash"
params.inject({}) do |h,(k,v)|
h[k.to_s.underscore.tr("-", "_")] = unrename_keys(v)
h[k.to_s.tr("-", "_")] = unrename_keys(v)
h
end
when "Array"

View file

@ -646,6 +646,22 @@ class HashToXmlTest < Test::Unit::TestCase
assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["rsp"]["photos"]["photo"]
end
def test_all_caps_key_from_xml
test_xml = <<-EOT
<ABC3XYZ>
<TEST>Lorem Ipsum</TEST>
</ABC3XYZ>
EOT
expected_hash = {
"ABC3XYZ" => {
"TEST" => "Lorem Ipsum"
}
}
assert_equal expected_hash, Hash.from_xml(test_xml)
end
def test_empty_array_from_xml
blog_xml = <<-XML
<blog>