diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-11-14 18:59:05 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-11-14 18:59:05 +0000 |
commit | 990a3f3a83ec6b33360373919009a7d8bd396534 (patch) | |
tree | 24111fefaca4821bdb212e0e21f17f0d634792e2 | |
parent | 40cc41931e953ecf0d16feaa93615e067b617c0f (diff) | |
download | rails-990a3f3a83ec6b33360373919009a7d8bd396534.tar.gz rails-990a3f3a83ec6b33360373919009a7d8bd396534.tar.bz2 rails-990a3f3a83ec6b33360373919009a7d8bd396534.zip |
Use rexml for some tests rather than string include? checks to account for unordered attributes. Closes #10164 [Catfish]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8142 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rwxr-xr-x | activerecord/test/base_test.rb | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index ee34d201b8..a95ee7cd8a 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -12,6 +12,7 @@ require 'fixtures/subscriber' require 'fixtures/keyboard' require 'fixtures/post' require 'fixtures/minimalistic' +require 'rexml/document' class Category < ActiveRecord::Base; end class Smarts < ActiveRecord::Base; end @@ -1543,28 +1544,48 @@ class BasicsTest < Test::Unit::TestCase end def test_to_xml - xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true) + xml = REXML::Document.new(topics(:first).to_xml(:indent => 0)) bonus_time_in_current_timezone = topics(:first).bonus_time.xmlschema written_on_in_current_timezone = topics(:first).written_on.xmlschema last_read_in_current_timezone = topics(:first).last_read.xmlschema - assert_equal "<topic>", xml.first(7) - assert xml.include?(%(<title>The First Topic</title>)) - assert xml.include?(%(<author-name>David</author-name>)) - assert xml.include?(%(<id type="integer">1</id>)) - assert xml.include?(%(<replies-count type="integer">1</replies-count>)) - assert xml.include?(%(<written-on type="datetime">#{written_on_in_current_timezone}</written-on>)) - assert xml.include?(%(<content type="yaml">--- Have a nice day\n</content>)) - assert xml.include?(%(<author-email-address>david@loudthinking.com</author-email-address>)) - assert xml.include?(%(<parent-id nil="true" type="integer"></parent-id>)) + + assert_equal "topic", xml.root.name + assert_equal "The First Topic" , xml.elements["//title"].text + assert_equal "David" , xml.elements["//author-name"].text + + assert_equal "1", xml.elements["//id"].text + assert_equal "integer" , xml.elements["//id"].attributes['type'] + + assert_equal "1", xml.elements["//replies-count"].text + assert_equal "integer" , xml.elements["//replies-count"].attributes['type'] + + assert_equal written_on_in_current_timezone, xml.elements["//written-on"].text + assert_equal "datetime" , xml.elements["//written-on"].attributes['type'] + + assert_equal "--- Have a nice day\n" , xml.elements["//content"].text + assert_equal "yaml" , xml.elements["//content"].attributes['type'] + + assert_equal "david@loudthinking.com", xml.elements["//author-email-address"].text + + assert_equal nil, xml.elements["//parent-id"].text + assert_equal "integer", xml.elements["//parent-id"].attributes['type'] + assert_equal "true", xml.elements["//parent-id"].attributes['nil'] + if current_adapter?(:SybaseAdapter, :SQLServerAdapter, :OracleAdapter) - assert xml.include?(%(<last-read type="datetime">#{last_read_in_current_timezone}</last-read>)) + assert_equal last_read_in_current_timezone, xml.elements["//last-read"].text + assert_equal "datetime" , xml.elements["//last-read"].attributes['type'] else - assert xml.include?(%(<last-read type="date">2004-04-15</last-read>)) + assert_equal "2004-04-15", xml.elements["//last-read"].text + assert_equal "date" , xml.elements["//last-read"].attributes['type'] end + # Oracle and DB2 don't have true boolean or time-only fields unless current_adapter?(:OracleAdapter, :DB2Adapter) - assert xml.include?(%(<approved type="boolean">false</approved>)), "Approved should be a boolean" - assert xml.include?(%(<bonus-time type="datetime">#{bonus_time_in_current_timezone}</bonus-time>)) + assert_equal "false", xml.elements["//approved"].text + assert_equal "boolean" , xml.elements["//approved"].attributes['type'] + + assert_equal bonus_time_in_current_timezone, xml.elements["//bonus-time"].text + assert_equal "datetime" , xml.elements["//bonus-time"].attributes['type'] end end |