mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make sure assert_select can assert body tag
This reverts commitf93df52845
, reversing changes made toa455e3f4e9
. Conflicts: actionpack/lib/action_controller/test_case.rb actionview/lib/action_view/test_case.rb
This commit is contained in:
parent
edc39ff756
commit
1b9e85dbbd
6 changed files with 35 additions and 13 deletions
|
@ -679,10 +679,6 @@ module ActionController
|
|||
klass.new
|
||||
end
|
||||
|
||||
def document_root_element
|
||||
html_document
|
||||
end
|
||||
|
||||
included do
|
||||
include ActionController::TemplateAssertions
|
||||
include ActionDispatch::Assertions
|
||||
|
@ -692,6 +688,10 @@ module ActionController
|
|||
|
||||
private
|
||||
|
||||
def document_root_element
|
||||
html_document.root
|
||||
end
|
||||
|
||||
def check_required_ivars
|
||||
# Sanity check for required instance variables so we can give an
|
||||
# understandable error message.
|
||||
|
|
|
@ -15,7 +15,7 @@ module ActionDispatch
|
|||
@html_document ||= if @response.content_type =~ /xml$/
|
||||
Nokogiri::XML::Document.parse(@response.body)
|
||||
else
|
||||
Nokogiri::HTML::DocumentFragment.parse(@response.body)
|
||||
Nokogiri::HTML::Document.parse(@response.body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -505,7 +505,7 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def document_root_element
|
||||
html_document
|
||||
html_document.root
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -292,7 +292,7 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
|
|||
assert_equal({}, cookies.to_hash)
|
||||
assert_equal "OK", body
|
||||
assert_equal "OK", response.body
|
||||
assert_kind_of Nokogiri::HTML::DocumentFragment, html_document
|
||||
assert_kind_of Nokogiri::HTML::Document, html_document
|
||||
assert_equal 1, request_count
|
||||
end
|
||||
end
|
||||
|
@ -308,7 +308,7 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
|
|||
assert_equal({}, cookies.to_hash)
|
||||
assert_equal "Created", body
|
||||
assert_equal "Created", response.body
|
||||
assert_kind_of Nokogiri::HTML::DocumentFragment, html_document
|
||||
assert_kind_of Nokogiri::HTML::Document, html_document
|
||||
assert_equal 1, request_count
|
||||
end
|
||||
end
|
||||
|
@ -368,7 +368,7 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
|
|||
assert_response :redirect
|
||||
assert_response :found
|
||||
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::DocumentFragment, html_document
|
||||
assert_kind_of Nokogiri::HTML::Document, html_document
|
||||
assert_equal 1, request_count
|
||||
|
||||
follow_redirect!
|
||||
|
|
|
@ -132,6 +132,14 @@ XML
|
|||
render :nothing => true
|
||||
end
|
||||
|
||||
def test_without_body
|
||||
render html: '<div class="foo"></div>'.html_safe
|
||||
end
|
||||
|
||||
def test_with_body
|
||||
render html: '<body class="foo"></body>'.html_safe
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_url(opts)
|
||||
|
@ -179,6 +187,19 @@ XML
|
|||
end
|
||||
end
|
||||
|
||||
def test_assert_select_without_body
|
||||
get :test_without_body
|
||||
|
||||
assert_select 'body', 0
|
||||
assert_select 'div.foo'
|
||||
end
|
||||
|
||||
def test_assert_select_with_body
|
||||
get :test_with_body
|
||||
|
||||
assert_select 'body.foo'
|
||||
end
|
||||
|
||||
def test_url_options_reset
|
||||
@controller = DefaultUrlOptionsCachingController.new
|
||||
get :test_url_options_reset
|
||||
|
|
|
@ -126,10 +126,6 @@ module ActionView
|
|||
end
|
||||
|
||||
# Need to experiment if this priority is the best one: rendered => output_buffer
|
||||
def document_root_element
|
||||
Nokogiri::HTML::DocumentFragment.parse(@rendered.blank? ? @output_buffer : @rendered)
|
||||
end
|
||||
|
||||
class RenderedViewsCollection
|
||||
def initialize
|
||||
@rendered_views ||= Hash.new { |hash, key| hash[key] = [] }
|
||||
|
@ -161,6 +157,11 @@ module ActionView
|
|||
|
||||
private
|
||||
|
||||
# Need to experiment if this priority is the best one: rendered => output_buffer
|
||||
def document_root_element
|
||||
Nokogiri::HTML::Document.parse(@rendered.blank? ? @output_buffer : @rendered).root
|
||||
end
|
||||
|
||||
def say_no_to_protect_against_forgery!
|
||||
_helpers.module_eval do
|
||||
remove_possible_method :protect_against_forgery?
|
||||
|
|
Loading…
Reference in a new issue