From 178880ef7c4953470453c258abccf99b98c92bb9 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 21 Apr 2007 14:12:05 +0000 Subject: Use XSD-compatible type names for Hash#to_xml and make the converters extendable #8047 [Tim Pope] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6546 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/array_ext_test.rb | 2 +- activesupport/test/core_ext/hash_ext_test.rb | 30 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 5a273b83d6..26bc232b81 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -126,7 +126,7 @@ class ArrayToXmlTests < Test::Unit::TestCase assert xml.include?(%(820497600000)), xml assert xml.include?(%(David)), xml assert xml.include?(%(31)), xml - assert xml.include?(%(1.0)), xml + assert xml.include?(%(1.0)), xml assert xml.include?(%(Jason)), xml end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 813e23af5f..ba121cc352 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -395,6 +395,8 @@ class HashToXmlTest < Test::Unit::TestCase --- \n1: should be an integer\n:message: Have a nice day\narray: \n- should-have-dashes: true\n should_have_underscores: true\n david@loudthinking.com + 1.5 + 135 EOT @@ -409,7 +411,9 @@ class HashToXmlTest < Test::Unit::TestCase :viewed_at => Time.utc(2003, 7, 16, 9, 28), :content => { :message => "Have a nice day", 1 => "should be an integer", "array" => [{ "should-have-dashes" => true, "should_have_underscores" => true }] }, :author_email_address => "david@loudthinking.com", - :parent_id => nil + :parent_id => nil, + :ad_revenue => BigDecimal("1.50"), + :optimum_viewing_angle => 135.0 }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["topic"] @@ -513,6 +517,30 @@ class HashToXmlTest < Test::Unit::TestCase assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["rsp"]["photos"]["photo"] end + def test_xsd_like_types_from_xml + bacon_xml = <<-EOT + + 0.5 + 12.50 + 1 + 2007-12-25T12:34:56+0000 + + YmFiZS5wbmc= + + EOT + + expected_bacon_hash = { + :weight => 0.5, + :chunky => true, + :price => BigDecimal("12.50"), + :expires_at => Time.utc(2007,12,25,12,34,56), + :notes => "", + :illustration => "babe.png" + }.stringify_keys + + assert_equal expected_bacon_hash, Hash.from_xml(bacon_xml)["bacon"] + end + def test_should_use_default_value_for_unknown_key hash_wia = HashWithIndifferentAccess.new(3) assert_equal 3, hash_wia[:new_key] -- cgit v1.2.3