diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-21 14:12:05 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-21 14:12:05 +0000 |
commit | 178880ef7c4953470453c258abccf99b98c92bb9 (patch) | |
tree | e8b6ba2b3a8ce903b9ccdf37d113d69136efe237 /activesupport/test/core_ext | |
parent | eb7a3045e3035d7de35a43297a4f36255e4f178d (diff) | |
download | rails-178880ef7c4953470453c258abccf99b98c92bb9.tar.gz rails-178880ef7c4953470453c258abccf99b98c92bb9.tar.bz2 rails-178880ef7c4953470453c258abccf99b98c92bb9.zip |
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
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 30 |
2 files changed, 30 insertions, 2 deletions
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?(%(<age-in-millis type="integer">820497600000</age-in-millis>)), xml assert xml.include?(%(<name>David</name>)), xml assert xml.include?(%(<age type="integer">31</age>)), xml - assert xml.include?(%(<age-in-millis type="numeric">1.0</age-in-millis>)), xml + assert xml.include?(%(<age-in-millis type="decimal">1.0</age-in-millis>)), xml assert xml.include?(%(<name>Jason</name>)), 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 <content type="yaml">--- \n1: should be an integer\n:message: Have a nice day\narray: \n- should-have-dashes: true\n should_have_underscores: true\n</content> <author-email-address>david@loudthinking.com</author-email-address> <parent-id></parent-id> + <ad-revenue type="decimal">1.5</ad-revenue> + <optimum-viewing-angle type="float">135</optimum-viewing-angle> </topic> 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 + <bacon> + <weight type="double">0.5</weight> + <price type="decimal">12.50</price> + <chunky type="boolean"> 1 </chunky> + <expires-at type="dateTime">2007-12-25T12:34:56+0000</expires-at> + <notes type="string"></notes> + <illustration type="base64Binary">YmFiZS5wbmc=</illustration> + </bacon> + 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] |