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

Closed
rehevkor5 opened this Issue Aug 27, 2012 · 1 comment

3 participants

@rehevkor5

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?

@pixeltrix
Ruby on Rails member

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.

@senny senny added a commit to senny/rails that referenced this issue Oct 1, 2012
@senny senny prefix TemplateAssertions ivars (#7459) bb0f4a1
@rafaelfranca rafaelfranca added a commit that referenced this issue Oct 31, 2012
@rafaelfranca 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