aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-09 21:12:28 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-09 21:12:28 +0000
commitd872281975b2bdcfcd06e21b55d78c8fb53ba5d1 (patch)
tree8d380e62fc9df44a12d0132dfcdd58046c05ab8a /activesupport/test/core_ext
parent966c276d6071f8c331f75820f8c2f30d1bba02b2 (diff)
downloadrails-d872281975b2bdcfcd06e21b55d78c8fb53ba5d1.tar.gz
rails-d872281975b2bdcfcd06e21b55d78c8fb53ba5d1.tar.bz2
rails-d872281975b2bdcfcd06e21b55d78c8fb53ba5d1.zip
Fixed to_xml across the board to use nice indention, better skip_attributes workings, no type on strings, and cleaned tests [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3829 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb28
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb45
2 files changed, 53 insertions, 20 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index 956c10665d..af566179e9 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -1,5 +1,5 @@
require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/array'
+require File.dirname(__FILE__) + '/../../lib/active_support'
class ArrayExtToParamTests < Test::Unit::TestCase
def test_string_array
@@ -71,10 +71,26 @@ end
class ArraToXmlTests < Test::Unit::TestCase
def test_to_xml
- a = [ { :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" } ]
- assert_equal(
- "<hashes><hash><street-address type=\"string\">Paulina</street-address><name type=\"string\">David</name></hash><hash><street-address type=\"string\">Evergreen</street-address><name type=\"string\">Jason</name></hash></hashes>",
- a.to_xml
- )
+ xml = [
+ { :name => "David", :age => 26 }, { :name => "Jason", :age => 31 }
+ ].to_xml(:skip_instruct => true, :indent => 0)
+
+ assert_equal "<hashes><hash>", xml.first(14)
+ 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_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 xml.include?(%(<street-address>Paulina</street-address>))
+ assert xml.include?(%(<name>David</name>))
+ assert xml.include?(%(<street-address>Evergreen</street-address>))
+ assert xml.include?(%(<name>Jason</name>))
end
end \ No newline at end of file
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index b7d024f754..1aa3838152 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -167,29 +167,46 @@ class HashExtTest < Test::Unit::TestCase
end
class HashToXmlTest < Test::Unit::TestCase
+ def setup
+ @xml_options = { :root => :person, :skip_instruct => true, :indent => 0 }
+ end
+
def test_one_level
- h = { :name => "David", :street => "Paulina" }
- assert_equal %(<person><street type="string">Paulina</street><name type="string">David</name></person>), h.to_xml(:root => :person)
+ xml = { :name => "David", :street => "Paulina" }.to_xml(@xml_options)
+ assert_equal "<person>", xml.first(8)
+ assert xml.include?(%(<street>Paulina</street>))
+ assert xml.include?(%(<name>David</name>))
end
def test_one_level_with_types
- h = { :name => "David", :street => "Paulina", :age => 26, :moved_on => Date.new(2005, 11, 15) }
- assert_equal(
- "<person><street type=\"string\">Paulina</street><name type=\"string\">David</name><age type=\"integer\">26</age><moved-on type=\"date\">2005-11-15</moved-on></person>",
- h.to_xml(:root => :person)
- )
+ xml = { :name => "David", :street => "Paulina", :age => 26, :moved_on => Date.new(2005, 11, 15) }.to_xml(@xml_options)
+ assert_equal "<person>", xml.first(8)
+ assert xml.include?(%(<street>Paulina</street>))
+ assert xml.include?(%(<name>David</name>))
+ assert xml.include?(%(<age type="integer">26</age>))
+ assert xml.include?(%(<moved-on type="date">2005-11-15</moved-on>))
end
def test_one_level_with_nils
- h = { :name => "David", :street => "Paulina", :age => nil }
- assert_equal(
- "<person><street type=\"string\">Paulina</street><name type=\"string\">David</name><age></age></person>",
- h.to_xml(:root => :person)
- )
+ xml = { :name => "David", :street => "Paulina", :age => nil }.to_xml(@xml_options)
+ assert_equal "<person>", xml.first(8)
+ assert xml.include?(%(<street>Paulina</street>))
+ assert xml.include?(%(<name>David</name>))
+ assert xml.include?(%(<age></age>))
+ end
+
+ def test_one_level_with_skipping_types
+ xml = { :name => "David", :street => "Paulina", :age => nil }.to_xml(@xml_options.merge(:skip_types => true))
+ assert_equal "<person>", xml.first(8)
+ assert xml.include?(%(<street>Paulina</street>))
+ assert xml.include?(%(<name>David</name>))
+ assert xml.include?(%(<age></age>))
end
def test_two_levels
- h = { :name => "David", :address => { :street => "Paulina" } }
- assert_equal %(<person><address><street type="string">Paulina</street></address><name type="string">David</name></person>), h.to_xml(:root => :person)
+ xml = { :name => "David", :address => { :street => "Paulina" } }.to_xml(@xml_options)
+ assert_equal "<person>", xml.first(8)
+ assert xml.include?(%(<address><street>Paulina</street></address>))
+ assert xml.include?(%(<name>David</name>))
end
end \ No newline at end of file