Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

a :partial option in assert_template

#1550

In one app I work on I have to spend a fair amount of test code ensuring that partials are rendered (or not) depending on user permissions and what data exists and so on and so forth. Until now I've just been writing helpers named tag_list_rendered and bookmark_toggle_rendered and such, all of which liberally use assert_select to divine if the output I want is there.

Right below all those helpers were assert_templates, and I realized just how more readable assert_template :partial => 'shared/_bookmark_toggle' would be than assert bookmark_toggle_rendered. So with this patch you can now do:

assert_template 'index' and assert_template nil like you can now.

assert_template :partial => '_name' to assert if it was rendered

assert_template :partial => '_name', :count => 14 to assert it was rendered a specific number of times

assert_template :partial => '_name', :count => 0 to assert that given partial was not rendered

assert_template :partial => false to assert that no partials were rendered.

Reported by dust · December 10th, 2008 @ 08:20 PM

State: resolved
Milestone: 2.x
Assigned to: josh josh
Importance: Low

Activity

  1. dust
    dust

    Apologies - this is the diff I meant to attach

    December 10th, 2008 @ 08:44 PM

  2. josh
    josh
    • Assigned user set to josh

    I'm down for adding support for this, but I have a few concerns.

    I'm mainly worried about performance. Tracking these counts hurts a little bit. And this data is only going to be used in tests. So your production env is still doing all this work and throwing it away.

    My ideal solution would be to monkey patch the render method when we start a testing env so it wouldn't affect production performance at all.

    Also, I really hate @_first_render, if you can knock that out too, that would be awesome.

    December 11th, 2008 @ 12:48 AM

  3. dust
    dust

    Alrighty, it now patches the tracking stuff in when actionview's test setup stuff is loaded.

    December 11th, 2008 @ 02:45 PM

  4. Repository
    Repository
    • State changed from new to resolved

    (from [49306ccacf01e36d444771d42321965616e226f0]) Add :partial option to assert_template [#1550 a :partial option in assert_template state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    December 11th, 2008 @ 05:07 PM

  5. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 7th, 2010 @ 04:55 PM