[rspec-users] Collection proxies need to be stubbed ?

David Chelimsky dchelimsky at gmail.com
Sun Jan 21 16:59:27 EST 2007


On 1/21/07, Francois Beausoleil <francois.beausoleil at gmail.com> 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.

RSpec is ALL ABOUT design, so these questions are certainly on topic
(in my view).

>
> 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