1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Parse HTML as document fragment.

This is to match the changes in Rails Dom Testing rails/rails-dom-testing#20.
This commit is contained in:
Kasper Timm Hansen 2014-09-29 21:41:52 +02:00
parent 035cc69c48
commit f939904f23
6 changed files with 9 additions and 7 deletions

View file

@ -2,6 +2,8 @@ source 'https://rubygems.org'
gemspec gemspec
gem 'rails-dom-testing', github: 'rails/rails-dom-testing'
# We need a newish Rake since Active Job sets its test tasks' descriptions. # We need a newish Rake since Active Job sets its test tasks' descriptions.
gem 'rake', '>= 10.3' gem 'rake', '>= 10.3'

View file

@ -689,7 +689,7 @@ module ActionController
private private
def document_root_element def document_root_element
html_document.root html_document
end end
def check_required_ivars def check_required_ivars

View file

@ -15,7 +15,7 @@ module ActionDispatch
@html_document ||= if @response.content_type =~ /xml$/ @html_document ||= if @response.content_type =~ /xml$/
Nokogiri::XML::Document.parse(@response.body) Nokogiri::XML::Document.parse(@response.body)
else else
Nokogiri::HTML::Document.parse(@response.body) Nokogiri::HTML::DocumentFragment.parse(@response.body)
end end
end end
end end

View file

@ -497,7 +497,7 @@ module ActionDispatch
end end
def document_root_element def document_root_element
html_document.root html_document
end end
end end
end end

View file

@ -292,7 +292,7 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
assert_equal({}, cookies.to_hash) assert_equal({}, cookies.to_hash)
assert_equal "OK", body assert_equal "OK", body
assert_equal "OK", response.body assert_equal "OK", response.body
assert_kind_of Nokogiri::HTML::Document, html_document assert_kind_of Nokogiri::HTML::DocumentFragment, html_document
assert_equal 1, request_count assert_equal 1, request_count
end end
end end
@ -308,7 +308,7 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
assert_equal({}, cookies.to_hash) assert_equal({}, cookies.to_hash)
assert_equal "Created", body assert_equal "Created", body
assert_equal "Created", response.body assert_equal "Created", response.body
assert_kind_of Nokogiri::HTML::Document, html_document assert_kind_of Nokogiri::HTML::DocumentFragment, html_document
assert_equal 1, request_count assert_equal 1, request_count
end end
end end
@ -368,7 +368,7 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
assert_response :redirect assert_response :redirect
assert_response :found assert_response :found
assert_equal "<html><body>You are being <a href=\"http://www.example.com/get\">redirected</a>.</body></html>", response.body assert_equal "<html><body>You are being <a href=\"http://www.example.com/get\">redirected</a>.</body></html>", response.body
assert_kind_of Nokogiri::HTML::Document, html_document assert_kind_of Nokogiri::HTML::DocumentFragment, html_document
assert_equal 1, request_count assert_equal 1, request_count
follow_redirect! follow_redirect!

View file

@ -158,7 +158,7 @@ module ActionView
# Need to experiment if this priority is the best one: rendered => output_buffer # Need to experiment if this priority is the best one: rendered => output_buffer
def document_root_element def document_root_element
Nokogiri::HTML::Document.parse(@rendered.blank? ? @output_buffer : @rendered).root Nokogiri::HTML::DocumentFragment.parse(@rendered.blank? ? @output_buffer : @rendered)
end end
def say_no_to_protect_against_forgery! def say_no_to_protect_against_forgery!