Adding some more tests for the new behaviour of partial collection counters
Reported by Cameron Yule | August 6th, 2008 @ 06:25 PM | in 2.2
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.
Comments and changes to this ticket
-
Frederick Cheung August 6th, 2008 @ 07:04 PM
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 ?
-
Cameron Yule August 6th, 2008 @ 07:58 PM
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.
-
Pratik August 6th, 2008 @ 08:41 PM
- → 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
-
Joshua Peek August 7th, 2008 @ 03:31 AM
- → Assigned user changed from to Joshua Peek
-
Joshua Peek August 7th, 2008 @ 03:47 AM
- → 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 -
Joshua Peek August 7th, 2008 @ 06:49 AM
- → Milestone changed from 2.x to 2.2
-
Cameron Yule August 7th, 2008 @ 08:19 AM
Hi Joshua, thanks for pointing that out!
Updated to correct the failing test (was simply an incorrect path).
-

Repository August 9th, 2008 @ 04:49 PM
- → State changed from open to resolved
(from [2faf35cea9846fdfa1099f5dfd1589d53a3daf3b]) Added tests for partial collection counters [#766 state:resolved] Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Source available from github
Repository is at http://github.com/rails/rails
Check out the development master (Edge Rails):
git clone git://github.com/rails/rails.git
Creating or reviewing a patch
See the contributor guide.
Creating a feature request
Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.
Creating a bug report
When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.
Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.
Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too"..
