Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4895

Show
Ignore:
Timestamp:
09/01/06 16:09:18 (2 years ago)
Author:
rick
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r4885 r4895  
    11*SVN* 
     2 
     3* Fix cases where empty xml nodes weren't being translated to nil in Hash.create_from_xml [Rick Olson] 
     4 
     5  <written-on type="date"></written-on> # => { :type => 'date' } # WRONG 
     6  <written-on type="date"></written-on> # => nil # RIGHT 
    27 
    38* Tighten rescue clauses.  #5985 [james@grayproductions.net] 
  • trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb

    r4616 r4895  
    102102                    end 
    103103                  else 
    104                     value.empty? || value['nil'] == 'true' ? nil : value.inject({}) do |h,(k,v)| 
     104                    (value.blank? || value['type'] || value['nil'] == 'true') ? nil : value.inject({}) do |h,(k,v)| 
    105105                      h[k] = typecast_xml_value(v) 
    106106                      h 
  • trunk/activesupport/test/core_ext/hash_ext_test.rb

    r4616 r4895  
    335335      :author_email_address => "david@loudthinking.com", 
    336336      :parent_id => nil 
     337    }.stringify_keys 
     338 
     339    assert_equal expected_topic_hash, Hash.create_from_xml(topic_xml)["topic"] 
     340  end 
     341 
     342  def test_single_record_from_xml_with_nil_values 
     343    topic_xml = <<-EOT 
     344      <topic> 
     345        <title></title> 
     346        <id type="integer"></id> 
     347        <approved type="boolean"></approved> 
     348        <written-on type="date"></written-on> 
     349        <viewed-at type="datetime"></viewed-at> 
     350        <parent-id></parent-id> 
     351      </topic> 
     352    EOT 
     353 
     354    expected_topic_hash = { 
     355      :title      => nil,  
     356      :id         => nil, 
     357      :approved   => nil, 
     358      :written_on => nil, 
     359      :viewed_at  => nil,  
     360      :parent_id  => nil 
    337361    }.stringify_keys 
    338362