[rspec-users] Collection proxies need to be stubbed ?
cwdinfo at gmail.com
Sun Jan 21 15:52:09 EST 2007
Do partial mocks solve your problem?
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.
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>
>>> def index
>>> @projects = current_user.projects.active
>> 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
>> ... 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'])
> has_many :projects
> def active_projects
> We're going off-topic here, but these are good design questions
> Thank you for enlightning me !
> Bye !
> François Beausoleil
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users