Changeset 5209
- Timestamp:
- 09/29/06 22:23:16 (3 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/array_ext_test.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/hash_ext_test.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r5197 r5209 1 1 *SVN* 2 3 * Hash#to_xml supports Bignum and BigDecimal. #6313 [edibiase] 2 4 3 5 * Don't undefine #class in OptionMerger [Rick] trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb
r5149 r5209 7 7 module Conversions 8 8 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" 16 18 } unless defined? XML_TYPE_NAMES 17 19 … … 57 59 value.to_xml(options.merge({ :root => key, :skip_instruct => true })) 58 60 else 59 type_name = XML_TYPE_NAMES[value.class ]61 type_name = XML_TYPE_NAMES[value.class.name] 60 62 61 63 key = dasherize ? key.to_s.dasherize : key.to_s trunk/activesupport/test/core_ext/array_ext_test.rb
r4900 r5209 1 1 require File.dirname(__FILE__) + '/../abstract_unit' 2 require 'bigdecimal' 2 3 3 4 class ArrayExtToParamTests < Test::Unit::TestCase … … 117 118 def test_to_xml 118 119 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') } 120 122 ].to_xml(:skip_instruct => true, :indent => 0) 121 123 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 127 131 end 128 132 129 133 def test_to_xml_with_dedicated_name 130 134 xml = [ 131 { :name => "David", :age => 26 }, { :name => "Jason", :age => 31 }135 { :name => "David", :age => 26, :age_in_millis => 820497600000 }, { :name => "Jason", :age => 31 } 132 136 ].to_xml(:skip_instruct => true, :indent => 0, :root => "people") 133 137 trunk/activesupport/test/core_ext/hash_ext_test.rb
r5149 r5209 256 256 257 257 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) 259 259 assert_equal "<person>", xml.first(8) 260 260 assert xml.include?(%(<street>Paulina</street>)) 261 261 assert xml.include?(%(<name>David</name>)) 262 262 assert xml.include?(%(<age type="integer">26</age>)) 263 assert xml.include?(%(<age-in-millis type="integer">820497600000</age-in-millis>)) 263 264 assert xml.include?(%(<moved-on type="date">2005-11-15</moved-on>)) 264 265 end … … 316 317 <approved type="boolean"> true </approved> 317 318 <replies-count type="integer">0</replies-count> 319 <replies-close-in type="integer">2592000000</replies-close-in> 318 320 <written-on type="date">2003-07-16</written-on> 319 321 <viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at> … … 330 332 :approved => true, 331 333 :replies_count => 0, 334 :replies_close_in => 2592000000, 332 335 :written_on => Date.new(2003, 7, 16), 333 336 :viewed_at => Time.utc(2003, 7, 16, 9, 28), … … 373 376 <approved type="boolean">false</approved> 374 377 <replies-count type="integer">0</replies-count> 378 <replies-close-in type="integer">2592000000</replies-close-in> 375 379 <written-on type="date">2003-07-16</written-on> 376 380 <viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at> … … 385 389 <approved type="boolean">false</approved> 386 390 <replies-count type="integer">0</replies-count> 391 <replies-close-in type="integer">2592000000</replies-close-in> 387 392 <written-on type="date">2003-07-16</written-on> 388 393 <viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at> … … 400 405 :approved => false, 401 406 :replies_count => 0, 407 :replies_close_in => 2592000000, 402 408 :written_on => Date.new(2003, 7, 16), 403 409 :viewed_at => Time.utc(2003, 7, 16, 9, 28),