Parse ActionView::TestCase#rendered
as DocumentFragment
#50584
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Background
To integrate with rails-dom-testing and its selector assertions,
ActionView::TestCase
defines a#document_root_element
method that parses the HTML into a fully valid HTML document and returns the "root".In the case of most Action View partials rendered with
render partial: "..."
, the resulting document would be invalid, so its constituent parts (its<html>
,<head>
, and<body>
elements) are synthesized during the parsing process. This results in a document whose contents are equivalent to the original HTML string, but whose structure is not.To share a concrete example:
Prior to this commit, the parsed HTML content returned from calling
rendered.html
relied on the same mechanisms as#document_root_element
, and parsed the HTML fragment into a full document, with a synthesized<html>
element as its root. Therendered.html
value should reflect the content that was rendered by the partial, and should not behave the same as#document_root_element
.When the parsing class is changed from Nokogiri::XML::Document to Nokogiri::XML::DocumentFragment, the returned value reflects the same exact content as what was rendered.
To elaborate on the previous example:
Detail
This commit changes the default
rendered.html
behavior to rely onNokogiri::XML::DocumentFragment
instead ofNokogiri::XML::Document
.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]