提交 990a3f3a 编写于 作者: J Jeremy Kemper

Use rexml for some tests rather than string include? checks to account for...

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
上级 40cc4193
......@@ -12,6 +12,7 @@
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 @@ def test_assert_queries
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册