aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-06-01 06:48:09 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-06-01 06:48:09 +0000
commit846e8587273743b5cc46708b3c0f047bb501fe02 (patch)
treed180fd4e04b1177b9771bfbeb29cce323b4adae2 /activesupport/test
parent83ce4c59be3d5f1f1246b46f53370f5f65fd0dc5 (diff)
downloadrails-846e8587273743b5cc46708b3c0f047bb501fe02.tar.gz
rails-846e8587273743b5cc46708b3c0f047bb501fe02.tar.bz2
rails-846e8587273743b5cc46708b3c0f047bb501fe02.zip
Added proper handling of arrays (closes #8537) [hasmanyjosh]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6924 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb4
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb39
2 files changed, 39 insertions, 4 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index e5ca4c424f..8c5356ac78 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -121,7 +121,7 @@ class ArrayToXmlTests < Test::Unit::TestCase
{ :name => "Jason", :age => 31, :age_in_millis => BigDecimal.new('1.0') }
].to_xml(:skip_instruct => true, :indent => 0)
- assert_equal "<records><record>", xml.first(17), xml
+ assert_equal '<records type="array"><record>', xml.first(30)
assert xml.include?(%(<age type="integer">26</age>)), xml
assert xml.include?(%(<age-in-millis type="integer">820497600000</age-in-millis>)), xml
assert xml.include?(%(<name>David</name>)), xml
@@ -135,7 +135,7 @@ class ArrayToXmlTests < Test::Unit::TestCase
{ :name => "David", :age => 26, :age_in_millis => 820497600000 }, { :name => "Jason", :age => 31 }
].to_xml(:skip_instruct => true, :indent => 0, :root => "people")
- assert_equal "<people><person>", xml.first(16)
+ assert_equal '<people type="array"><person>', xml.first(29)
end
def test_to_xml_with_options
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index a428fe5061..73b873aee8 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -370,7 +370,7 @@ class HashToXmlTest < Test::Unit::TestCase
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?(%(<addresses type="array"><address>))
assert xml.include?(%(<address><street>Paulina</street></address>))
assert xml.include?(%(<address><street>Evergreen</street></address>))
assert xml.include?(%(<name>David</name>))
@@ -378,7 +378,7 @@ class HashToXmlTest < Test::Unit::TestCase
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>))
+ assert xml.include?(%(<addresses type="array"><address><streets type="array"><street><name>))
end
def test_single_record_from_xml
@@ -516,6 +516,41 @@ class HashToXmlTest < Test::Unit::TestCase
assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["rsp"]["photos"]["photo"]
end
+
+ def test_empty_array_from_xml
+ blog_xml = <<-XML
+ <blog>
+ <posts type="array"></posts>
+ </blog>
+ XML
+ expected_blog_hash = {"blog" => {"posts" => []}}
+ assert_equal expected_blog_hash, Hash.from_xml(blog_xml)
+ end
+
+ def test_array_with_one_entry_from_xml
+ blog_xml = <<-XML
+ <blog>
+ <posts type="array">
+ <post>a post</post>
+ </posts>
+ </blog>
+ XML
+ expected_blog_hash = {"blog" => {"posts" => ["a post"]}}
+ assert_equal expected_blog_hash, Hash.from_xml(blog_xml)
+ end
+
+ def test_array_with_multiple_entries_from_xml
+ blog_xml = <<-XML
+ <blog>
+ <posts type="array">
+ <post>a post</post>
+ <post>another post</post>
+ </posts>
+ </blog>
+ XML
+ expected_blog_hash = {"blog" => {"posts" => ["a post", "another post"]}}
+ assert_equal expected_blog_hash, Hash.from_xml(blog_xml)
+ end
def test_xsd_like_types_from_xml
bacon_xml = <<-EOT