Avdi Grimm wrote: > Marnen Laibow-Koser wrote: >> And there's an argument to be made that since the AR framework is part >> of an AR class, it must be respected -- and hit *some* state-preserving >> DB-like thing -- to properly unit test an AR class. > > This is the kind of muddling of concepts that I think Rails encourages. > The idea that "Model == Database Thingy".
That's not an idea that I have. I used to do MVC without an ORM (and indeed, without "official" objects), and I'm quite used to writing non-AR models in Rails. > At every opportunity I > encourage developers to start their apps with bare, pure Ruby models and > only add "< ActiveRecord::Base" in a later iteration. That seems like more trouble than it's worth with Rails, but I'll think about how I'd try that. > This practice > helps to start thinking of your objects purely in terms of how they > model your domain - which is how OO is supposed to work. No argument there. [...] > Of course, AR makes it harder to think of it as a collaborator because > you have to inherit from it and it adds all sorts of methods to self and > imposes arbitrary rules like "no initializers". But if you are careful > you can still think of it as a (rather pushy) collaborator and structure > your tests accordingly - separating the tests of persistence from the > tests of logic. Again, I do that anyway. But if I'm testing features that touch the persistence layer, then I want an actual persistence layer to talk to, not just a black hole. And the way Rails structures its objects, I think that's still a unit test. If Rails worked a bit differently and used a separate persistence library instead of an ORM, then I'd agree with you on the appropriate way to test AR objects. But it doesn't, so I think I don't. > > I'll add a post about the how and the why and the benefits of this kind > of strict separation to my queue on Virtuous Code. I will be interested to read that. At the moment, this separation just seems like fighting Rails to no advantage and some potential harm. > > -- > Avdi Best, -- Marnen Laibow-Koser http://www.marnen.org [email protected] -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

