[rspec-users] Collection proxies need to be stubbed ?
dchelimsky at gmail.com
Sun Jan 21 18:58:16 EST 2007
On 1/21/07, Brian Yamabe <brian at yamabe.net> wrote:
> David, thanks for making me think.
> If the bi-directional dependency
> is needed, would it be cleaned up with a "has_many :through" (An
> Assignment class as an example)?
That happens to work in a lot of cases because rails supports it. But
bear in mind that :through relationships weren't supported in 1.0.
They came later because the problem of a particular type of
relationship came up enough to do something about it in the framework.
I'm sure that sooner or later you're going to come up w/ a model that
isn't supported directly by rails, and then you need to think about
all this stuff.
Also, while this may be far from most people's minds, letting all of
this AR goodness seep out past your model classes binds your
application to AR. There are other persistence frameworks, like OG,
that are promising. If you decided to give on a try, you'd have a much
easier time if you encapsulate all of that goodness inside your models
and expose methods that are framework neutral.
Not saying that you shouldn't exploit AR goodness. Just that
localizing the exploitation makes things more flexible in the long
> > def self.find_active_projects_for_user(user)
> > return user.projects.active_projects
> > end
> > This bi-directional dependency seems problematic to me. I realize that
> > rails makes it easy to do these, but again, just because its easy
> > doesn't make it a good decision.
> > This is one of those questions that can be enlightened by client need.
> > Do clients of Projects ask for their users? Do clients of User ask for
> > its Projects? If both answers are yes, then maybe the bi-directional
> > deal makes sense. If only one is needed, then only one should be
> > implemented.
> > OK. I'll shut up now. Go Bears!
> > David
> >> ---Brian Yamabe
> >> On Jan 21, 2007, at 12:53 PM, Jay Levitt wrote:
> >>> Francois Beausoleil wrote:
> >>>> 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 ?
> >>> This seems to be a basic conflict between "Tell, don't ask" and
> >>> domain-driven design. DDD, as I understand it, says the Project
> >>> class
> >>> should encapsulate all knowledge about projects; TDA says we
> >>> shouldn't
> >>> ask for the project proxy. Yes?
> >>> Jay
> >>> _______________________________________________
> >>> rspec-users mailing list
> >>> rspec-users at rubyforge.org
> >>> http://rubyforge.org/mailman/listinfo/rspec-users
> >> _______________________________________________
> >> rspec-users mailing list
> >> rspec-users at rubyforge.org
> >> http://rubyforge.org/mailman/listinfo/rspec-users
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users