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.

Adding some more tests for the new behaviour of partial collection counters

#766

There's been changes made to partial collection counters between Rails 2.1 and Edge which haven't been fully tested.

In Rails 2.1, render :partial => 'sometemplate', with no collection parameter being passed in, still results in sometemplate_counter being set as a local variable with a value of 0.

This behaviour is no longer the same in Edge rails, where the counter is only generated for partials with a collection. This is a good change, as it allows for the counter to be over-ridden by passing in your own local variable (e.g. when you're adding new elements to a pre-rendered list via AJAX).

See this thread on the the Rails Core mailing list for more information;

http://groups.google.com/group/r...

I've attempted to write a few tests to check for this behaviour.

Reported by Cameron Yule · August 6th, 2008 @ 06:25 PM

State: resolved
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. Frederick Cheung
    Frederick Cheung

    Am I missing something or is the second test not duplicating the already existing test test_partial_collection_with_counter ?

    Also would it not be preferable if the first test asserted what we're really interested in: that the value from :locals is taken into account, rather a side effect of it (an error being raised if :locals doesn't specify a value ?

    August 6th, 2008 @ 07:04 PM

  2. Cameron Yule
    Cameron Yule

    Hi Frederick, thanks for the reply. You're entirely correct, I'd duped another test, and the value from :locals being taken into account is of course the logical thing to test as opposed to the error being raised.

    Updated the patch with changes to reflect your suggestions, hopefully it's more suitable.

    August 6th, 2008 @ 07:58 PM

  3. Pratik
    Pratik
    • Title changed from [PATCH] Adding some more tests for the new behaviour of partial collection counters to Adding some more tests for the new behaviour of partial collection counters

    August 6th, 2008 @ 08:41 PM

  4. josh
    josh
    • Assigned user set to josh

    August 7th, 2008 @ 03:31 AM

  5. josh
    josh
    • State changed from new to open

    Its really awesome that you found this. I also surprised to "good" features accidentally added by the refactoring.

    However, I do get a test failure after I applied it.

    
    test_render_partial_with_locals(ViewRenderTest):
    NoMethodError: undefined method `controller_path' for NilClass:Class
    

    August 7th, 2008 @ 03:47 AM

  6. josh
    josh
    • Milestone cleared.

    August 7th, 2008 @ 06:49 AM

  7. Cameron Yule
    Cameron Yule

    Hi Joshua, thanks for pointing that out!

    Updated to correct the failing test (was simply an incorrect path).

    August 7th, 2008 @ 08:19 AM

  8. Repository
    Repository
    • State changed from open to resolved

    (from [2faf35cea9846fdfa1099f5dfd1589d53a3daf3b]) Added tests for partial collection counters [#766 Adding some more tests for the new behaviour of partial collection counters state:resolved] Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    August 9th, 2008 @ 04:49 PM