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

Fix cases where empty xml nodes weren't being translated to nil in Hash.create_from_xml [Rick Olson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4895 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Rick Olson 2006-09-01 16:09:18 +00:00
parent 5f175edde5
commit e4a4287c97
3 changed files with 30 additions and 1 deletions

View file

@ -1,5 +1,10 @@
*SVN*
* Fix cases where empty xml nodes weren't being translated to nil in Hash.create_from_xml [Rick Olson]
<written-on type="date"></written-on> # => { :type => 'date' } # WRONG
<written-on type="date"></written-on> # => nil # RIGHT
* Tighten rescue clauses. #5985 [james@grayproductions.net]
* Inflections: don't singularize -ies plurals. [foamdino@gmail.com, Mark Van Holstyn]

View file

@ -101,7 +101,7 @@ module ActiveSupport #:nodoc:
else content
end
else
value.empty? || value['nil'] == 'true' ? nil : value.inject({}) do |h,(k,v)|
(value.blank? || value['type'] || value['nil'] == 'true') ? nil : value.inject({}) do |h,(k,v)|
h[k] = typecast_xml_value(v)
h
end

View file

@ -339,6 +339,30 @@ class HashToXmlTest < Test::Unit::TestCase
assert_equal expected_topic_hash, Hash.create_from_xml(topic_xml)["topic"]
end
def test_single_record_from_xml_with_nil_values
topic_xml = <<-EOT
<topic>
<title></title>
<id type="integer"></id>
<approved type="boolean"></approved>
<written-on type="date"></written-on>
<viewed-at type="datetime"></viewed-at>
<parent-id></parent-id>
</topic>
EOT
expected_topic_hash = {
:title => nil,
:id => nil,
:approved => nil,
:written_on => nil,
:viewed_at => nil,
:parent_id => nil
}.stringify_keys
assert_equal expected_topic_hash, Hash.create_from_xml(topic_xml)["topic"]
end
def test_multiple_records_from_xml
topics_xml = <<-EOT
<topics>