From ea9bc06c9a47b839d5e2db94ba6bf7e29c8f0ae9 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 20 Oct 2015 16:08:56 -0600 Subject: Merge pull request #20715 from simsalabim/feature/parse-rss-atom-as-xml parse RSS/ATOM responses as XML, not HTML --- actionpack/CHANGELOG.md | 4 +++ .../lib/action_dispatch/testing/assertions.rb | 2 +- actionpack/test/controller/integration_test.rb | 30 ++++++++++++---------- 3 files changed, 22 insertions(+), 14 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 58af62ee76..a3b4f6e989 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,7 @@ +* Parse RSS/ATOM responses as XML, not HTML. + + *Alexander Kaupanin* + * Show helpful message in `BadRequest` exceptions due to invalid path parameter encodings. diff --git a/actionpack/lib/action_dispatch/testing/assertions.rb b/actionpack/lib/action_dispatch/testing/assertions.rb index 8dd0bd63ad..715d94d406 100644 --- a/actionpack/lib/action_dispatch/testing/assertions.rb +++ b/actionpack/lib/action_dispatch/testing/assertions.rb @@ -12,7 +12,7 @@ module ActionDispatch 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) diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index de7e800ac1..99f6f540a8 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -402,6 +402,8 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest format.html { render plain: "OK", status: 200 } format.js { render plain: "JS OK", status: 200 } format.xml { render :xml => "", :status => 200 } + format.rss { render :xml => "", :status => 200 } + format.atom { render :xml => "", :status => 200 } end end @@ -458,19 +460,21 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest end end - def test_get_xml - with_test_route_set do - get "/get", params: {}, headers: {"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 "", body - assert_equal "", 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 "", body + assert_equal "", response.body + assert_instance_of Nokogiri::XML::Document, html_document + assert_equal 1, request_count + end end end -- cgit v1.2.3