[rspec-users] Associations should be private
dchelimsky at gmail.com
Wed Oct 1 09:11:55 EDT 2008
On Wed, Oct 1, 2008 at 7:54 AM, Ashley Moran
<ashley.moran at patchspace.co.uk> wrote:
> The discussion among me, David, Michael, and Pat got me thinking.
> Specifically this by Michael:
>> Just my $0.02, but I really like specs to be treated as specifications for
>> what SHOULD be happening, not pretending other code is different than it is.
> This made me think the real solution is for ActiveRecord/A N Other ORM to
> declare that its associations are proxies and not arrays. But that's
> *terrible*, because it's encouraging users to manipulate the ORM objects'
> So what if you flatly make all associations private? Is this a good idea?
> Has anyone tried it?
It's been a while since I've taken a look at it, but Luke Redpath has
a plugin called Demeter's Revenge
that actually manages this all for you by adding methods like
team.add_player that wrap chains like team.players.add. It's a year
old and I don't know if it works w/ the latest rails updates or not.
I think that if you're actually writing a bunch of boilerplate code
the same way over and over without a plugin like that, then it's
probably painful. With something like that it's painless and
expressive and seriously cleans up your controller code examples.
Glancing at github, I see one other library up there that tries to
solve the same problem. Will have to look closer later at
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users