Skip to content
This repository

ActionController::TemplateAssertions pollutes @partials, @templates, and @layouts #7459

Closed
rehevkor5 opened this Issue · 1 comment

3 participants

Shannon Carey Andrew White Rafael Mendonça França
Shannon Carey

I just tracked a strange problem I was having with my view specs to ActionController::TemplateAssertions. It is using instance variables @partials, @templates, and @layouts on the test itself. I was populating the @templates variable, which is what my view expects to receive. Since TemplateAssertions doesn't expect this, it fails with a "can't convert" error.

TemplateAssertion's internal variables should not be mixed into the test itself. Agree/disagree?

Andrew White
Owner

You need some instance variables to track which templates, partials and layouts have been rendered otherwise the assertions wouldn't work, however they should certainly be prefixed with an underscore to help prevent clashes.

Yves Senn senny referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Yves Senn senny referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Yves Senn senny referenced this issue from a commit in senny/rails
Yves Senn senny prefix TemplateAssertions ivars (#7459) bb0f4a1
Rafael Mendonça França rafaelfranca referenced this issue from a commit
Rafael Mendonça França rafaelfranca Revert "Merge pull request #7797 from senny/7459_prefix_tempalte_asse…
…rtion_variables"

This reverts commit 2bad605.

Conflicts:
	actionpack/CHANGELOG.md

Reason: This added a regression related with shoulda-matchers, since it
is expecting the instance variable @layouts

See https://github.com/thoughtbot/shoulda-matchers/blob/9e1188eea68c47d9a56ce6280e45027da6187ab1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb#L74

This will introduce back #7459 but this stable release will be backward compatible.
Related with #8068.
6b7cd20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.