[rspec-users] Collection proxies need to be stubbed ?
s.ross
cwdinfo at gmail.com
Sun Jan 21 15:52:09 EST 2007
Do partial mocks solve your problem?
http://rspec.rubyforge.org/documentation/mocks/partial_mocks.html
I run into a lot of these issues when spec'ing, and it seems writing
mocks that cover as many cases as I expect AR to cough up can be
difficult. Others might have different experiences. I found partial
mocks intriguing, although I've not yet explored them.
Hope I'm not barking up the wrong tree.
--steve
On Jan 21, 2007, at 12:42 PM, Francois Beausoleil wrote:
> Hello David, all,
>
> 2007/1/21, David Chelimsky <dchelimsky at gmail.com>:
>> On 1/20/07, Francois Beausoleil <francois.beausoleil at gmail.com>
>> wrote:
>>> def index
>>> @projects = current_user.projects.active
>>> end
>>
>> I would approach this quite differently. The first difference being I
>> would have started with a spec, letting the spec help me to discover
>> the interface that I want on User.
>>
>> def index
>> @projects = current_user.active_projects
>> end
>>
>> ... which would, in turn, lead me to spec out a method named
>> active_projects on User.
>
> I agree with you, David, but Rails has this nice facility for allowing
> developers to add methods on collection proxies. The end goal is that
> I get only active / inactive projects, right ? Whatever
> implementation floats the boat is good.
>
> Adding #active_projects on User leads to a kind of namespace
> pollution, no ? Really, who knows what projects are active ? The
> Project class, or the User ?
>
> has_many :projects do
> def active
> find(:all, :conditions => ['active = 1'])
> end
> end
>
> has_many :projects
> def active_projects
>
> end
>
> We're going off-topic here, but these are good design questions
> anyway.
>
> Thank you for enlightning me !
>
> Bye !
> --
> François Beausoleil
> http://blog.teksol.info/
> http://piston.rubyforge.org/
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
More information about the rspec-users
mailing list