Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#20710 parse RSS/ATOM responses as XML, not HTML #20715

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/testing/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Assertions
include Rails::Dom::Testing::Assertions

def html_document
@html_document ||= if @response.content_type === Mime::XML
@html_document ||= if @response.content_type.to_s =~ /xml$/
Nokogiri::XML::Document.parse(@response.body)
else
Nokogiri::HTML::Document.parse(@response.body)
Expand Down
30 changes: 17 additions & 13 deletions actionpack/test/controller/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ def get
format.html { render :text => "OK", :status => 200 }
format.js { render :text => "JS OK", :status => 200 }
format.xml { render :xml => "<root></root>", :status => 200 }
format.rss { render :xml => "<root></root>", :status => 200 }
format.atom { render :xml => "<root></root>", :status => 200 }
end
end

Expand Down Expand Up @@ -303,19 +305,21 @@ def test_get
end
end

def test_get_xml
with_test_route_set do
get "/get", {}, {"HTTP_ACCEPT" => "application/xml"}
assert_equal 200, status
assert_equal "OK", status_message
assert_response 200
assert_response :success
assert_response :ok
assert_equal({}, cookies.to_hash)
assert_equal "<root></root>", body
assert_equal "<root></root>", response.body
assert_instance_of Nokogiri::XML::Document, html_document
assert_equal 1, request_count
def test_get_xml_rss_atom
%w[ application/xml application/rss+xml application/atom+xml ].each do |mime_string|
with_test_route_set do
get "/get", {}, {"HTTP_ACCEPT" => mime_string}
assert_equal 200, status
assert_equal "OK", status_message
assert_response 200
assert_response :success
assert_response :ok
assert_equal({}, cookies.to_hash)
assert_equal "<root></root>", body
assert_equal "<root></root>", response.body
assert_instance_of Nokogiri::XML::Document, html_document
assert_equal 1, request_count
end
end
end

Expand Down