Permalink
Browse files

Fix assert_select for XML documents. Closes #8173. [dasil003]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7417 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent fe31f0e commit 32553a2d76f4520e1456d5463c691310c22ebd2b @NZKoz NZKoz committed Sep 8, 2007
Showing with 26 additions and 1 deletion.
  1. +2 −1 actionpack/lib/action_controller/test_process.rb
  2. +24 −0 actionpack/test/controller/test_test.rb
@@ -449,7 +449,8 @@ def build_request_uri(action, parameters)
end
def html_document
- @html_document ||= HTML::Document.new(@response.body)
+ xml = @response.content_type =~ /xml$/
+ @html_document ||= HTML::Document.new(@response.body, false, xml)
end
def find_tag(conditions)
@@ -45,6 +45,16 @@ def test_html_output
</html>
HTML
end
+
+ def test_xml_output
+ response.content_type = "application/xml"
+ render :text => <<XML
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <area>area is an empty tag in HTML, raising an error if not in xml mode</area>
+</root>
+XML
+ end
def test_only_one_param
render :text => (params[:left] && params[:right]) ? "EEP, Both here!" : "OK"
@@ -301,6 +311,20 @@ def test_assert_tag_children_without_content
:children => { :count => 1,
:only => { :tag => "img" } } } }
end
+
+ def test_should_not_impose_childless_html_tags_in_xml
+ process :test_xml_output
+
+ begin
+ $stderr = StringIO.new
+ assert_select 'area' #This will cause a warning if content is processed as HTML
+ $stderr.rewind && err = $stderr.read
+ ensure
+ $stderr = STDERR
+ end
+
+ assert err.empty?
+ end
def test_assert_tag_attribute_matching
@response.body = '<input type="text" name="my_name">'

0 comments on commit 32553a2

Please sign in to comment.