diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-09 23:35:43 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-09 23:35:43 +0000 |
commit | 0c6d1785529ab2f9c86908f03a10c871512311e5 (patch) | |
tree | 544d3d4ad3aa218db856941aa581ab17352fb498 /activesupport/test | |
parent | d872281975b2bdcfcd06e21b55d78c8fb53ba5d1 (diff) | |
download | rails-0c6d1785529ab2f9c86908f03a10c871512311e5.tar.gz rails-0c6d1785529ab2f9c86908f03a10c871512311e5.tar.bz2 rails-0c6d1785529ab2f9c86908f03a10c871512311e5.zip |
Implemented nested to_xml and named elements for array xmling [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3830 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 12 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 15 |
2 files changed, 25 insertions, 2 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index af566179e9..0df27fde66 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -75,19 +75,27 @@ class ArraToXmlTests < Test::Unit::TestCase { :name => "David", :age => 26 }, { :name => "Jason", :age => 31 } ].to_xml(:skip_instruct => true, :indent => 0) - assert_equal "<hashes><hash>", xml.first(14) + assert_equal "<records><record>", xml.first(17) assert xml.include?(%(<age type="integer">26</age>)) assert xml.include?(%(<name>David</name>)) assert xml.include?(%(<age type="integer">31</age>)) assert xml.include?(%(<name>Jason</name>)) end + + def test_to_xml_with_dedicated_name + xml = [ + { :name => "David", :age => 26 }, { :name => "Jason", :age => 31 } + ].to_xml(:skip_instruct => true, :indent => 0, :root => "people") + + assert_equal "<people><person>", xml.first(16) + end def test_to_xml_with_options xml = [ { :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" } ].to_xml(:skip_instruct => true, :skip_types => true, :indent => 0) - assert_equal "<hashes><hash>", xml.first(14) + assert_equal "<records><record>", xml.first(17) assert xml.include?(%(<street-address>Paulina</street-address>)) assert xml.include?(%(<name>David</name>)) assert xml.include?(%(<street-address>Evergreen</street-address>)) diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 1aa3838152..43b0b29216 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -209,4 +209,19 @@ class HashToXmlTest < Test::Unit::TestCase assert xml.include?(%(<address><street>Paulina</street></address>)) assert xml.include?(%(<name>David</name>)) end + + def test_two_levels_with_array + xml = { :name => "David", :addresses => [{ :street => "Paulina" }, { :street => "Evergreen" }] }.to_xml(@xml_options) + assert_equal "<person>", xml.first(8) + assert xml.include?(%(<addresses><address>)) + assert xml.include?(%(<address><street>Paulina</street></address>)) + assert xml.include?(%(<address><street>Evergreen</street></address>)) + assert xml.include?(%(<name>David</name>)) + end + + + def test_three_levels_with_array + xml = { :name => "David", :addresses => [{ :streets => [ { :name => "Paulina" }, { :name => "Paulina" } ] } ] }.to_xml(@xml_options) + assert xml.include?(%(<addresses><address><streets><street><name>)) + end end
\ No newline at end of file |