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

Compare content_type with Mime::XML instead of regexp #19351

Merged
merged 1 commit into from
Mar 18, 2015
Merged
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 =~ /xml$/
@html_document ||= if @response.content_type === Mime::XML
Nokogiri::XML::Document.parse(@response.body)
else
Nokogiri::HTML::Document.parse(@response.body)
Expand Down
17 changes: 17 additions & 0 deletions actionpack/test/controller/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def get
respond_to do |format|
format.html { render :text => "OK", :status => 200 }
format.js { render :text => "JS OK", :status => 200 }
format.xml { render :xml => "<root></root>", :status => 200 }
end
end

Expand Down Expand Up @@ -419,6 +420,22 @@ 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
end
end

def test_post
with_test_route_set do
post '/post'
Expand Down