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

Changeset 5209

Show
Ignore:
Timestamp:
09/29/06 22:23:16 (3 years ago)
Author:
bitsweat
Message:

Hash#to_xml supports Bignum and BigDecimal. Closes #6313.

Files:

Legend:

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

    r5197 r5209  
    11*SVN* 
     2 
     3* Hash#to_xml supports Bignum and BigDecimal.  #6313 [edibiase] 
    24 
    35* Don't undefine #class in OptionMerger [Rick] 
  • trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb

    r5149 r5209  
    77      module Conversions 
    88        XML_TYPE_NAMES = { 
    9           ::Fixnum     => "integer", 
    10           ::Float      => "float", 
    11           ::Date       => "date", 
    12           ::DateTime   => "datetime", 
    13           ::Time       => "datetime", 
    14           ::TrueClass  => "boolean", 
    15           ::FalseClass => "boolean" 
     9          "Fixnum"     => "integer", 
     10          "Bignum"     => "integer", 
     11          "BigDecimal" => "numeric", 
     12          "Float"      => "float", 
     13          "Date"       => "date", 
     14          "DateTime"   => "datetime", 
     15          "Time"       => "datetime", 
     16          "TrueClass"  => "boolean", 
     17          "FalseClass" => "boolean" 
    1618        } unless defined? XML_TYPE_NAMES 
    1719 
     
    5759                    value.to_xml(options.merge({ :root => key, :skip_instruct => true })) 
    5860                  else 
    59                     type_name = XML_TYPE_NAMES[value.class
     61                    type_name = XML_TYPE_NAMES[value.class.name
    6062 
    6163                    key = dasherize ? key.to_s.dasherize : key.to_s 
  • trunk/activesupport/test/core_ext/array_ext_test.rb

    r4900 r5209  
    11require File.dirname(__FILE__) + '/../abstract_unit' 
     2require 'bigdecimal' 
    23 
    34class ArrayExtToParamTests < Test::Unit::TestCase 
     
    117118  def test_to_xml 
    118119    xml = [ 
    119       { :name => "David", :age => 26 }, { :name => "Jason", :age => 31 } 
     120      { :name => "David", :age => 26, :age_in_millis => 820497600000 }, 
     121      { :name => "Jason", :age => 31, :age_in_millis => BigDecimal.new('1.0') } 
    120122    ].to_xml(:skip_instruct => true, :indent => 0) 
    121123 
    122     assert_equal "<records><record>", xml.first(17) 
    123     assert xml.include?(%(<age type="integer">26</age>)) 
    124     assert xml.include?(%(<name>David</name>)) 
    125     assert xml.include?(%(<age type="integer">31</age>)) 
    126     assert xml.include?(%(<name>Jason</name>)) 
     124    assert_equal "<records><record>", xml.first(17), xml 
     125    assert xml.include?(%(<age type="integer">26</age>)), xml 
     126    assert xml.include?(%(<age-in-millis type="integer">820497600000</age-in-millis>)), xml 
     127    assert xml.include?(%(<name>David</name>)), xml 
     128    assert xml.include?(%(<age type="integer">31</age>)), xml 
     129    assert xml.include?(%(<age-in-millis type="numeric">1.0</age-in-millis>)), xml 
     130    assert xml.include?(%(<name>Jason</name>)), xml 
    127131  end 
    128132 
    129133  def test_to_xml_with_dedicated_name 
    130134    xml = [ 
    131       { :name => "David", :age => 26 }, { :name => "Jason", :age => 31 } 
     135      { :name => "David", :age => 26, :age_in_millis => 820497600000 }, { :name => "Jason", :age => 31 } 
    132136    ].to_xml(:skip_instruct => true, :indent => 0, :root => "people") 
    133137 
  • trunk/activesupport/test/core_ext/hash_ext_test.rb

    r5149 r5209  
    256256 
    257257  def test_one_level_with_types 
    258     xml = { :name => "David", :street => "Paulina", :age => 26, :moved_on => Date.new(2005, 11, 15) }.to_xml(@xml_options) 
     258    xml = { :name => "David", :street => "Paulina", :age => 26, :age_in_millis => 820497600000, :moved_on => Date.new(2005, 11, 15) }.to_xml(@xml_options) 
    259259    assert_equal "<person>", xml.first(8) 
    260260    assert xml.include?(%(<street>Paulina</street>)) 
    261261    assert xml.include?(%(<name>David</name>)) 
    262262    assert xml.include?(%(<age type="integer">26</age>)) 
     263    assert xml.include?(%(<age-in-millis type="integer">820497600000</age-in-millis>)) 
    263264    assert xml.include?(%(<moved-on type="date">2005-11-15</moved-on>)) 
    264265  end 
     
    316317        <approved type="boolean"> true </approved> 
    317318        <replies-count type="integer">0</replies-count> 
     319        <replies-close-in type="integer">2592000000</replies-close-in> 
    318320        <written-on type="date">2003-07-16</written-on> 
    319321        <viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at> 
     
    330332      :approved => true, 
    331333      :replies_count => 0, 
     334      :replies_close_in => 2592000000, 
    332335      :written_on => Date.new(2003, 7, 16), 
    333336      :viewed_at => Time.utc(2003, 7, 16, 9, 28), 
     
    373376          <approved type="boolean">false</approved> 
    374377          <replies-count type="integer">0</replies-count> 
     378          <replies-close-in type="integer">2592000000</replies-close-in> 
    375379          <written-on type="date">2003-07-16</written-on> 
    376380          <viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at> 
     
    385389          <approved type="boolean">false</approved> 
    386390          <replies-count type="integer">0</replies-count> 
     391          <replies-close-in type="integer">2592000000</replies-close-in> 
    387392          <written-on type="date">2003-07-16</written-on> 
    388393          <viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at> 
     
    400405      :approved => false, 
    401406      :replies_count => 0, 
     407      :replies_close_in => 2592000000, 
    402408      :written_on => Date.new(2003, 7, 16), 
    403409      :viewed_at => Time.utc(2003, 7, 16, 9, 28),