From: "David A. Black" Date: 2008-08-05T11:04:18+09:00 Subject: Re: unit testing advice Hi -- On Tue, 5 Aug 2008, Phlip wrote: > David A. Black wrote: > >> Just another follow-up (see also my earlier post, which addresses your >> concerns directly): there's a new screencast at railscasts.com today, >> on exactly that topic: models that are not ActiveRecord models. It's >> here: >> >> http://media.railscasts.com/videos/121_non_active_record_model.mov >> >> I'm glad to see it, as this is something that people often don't >> realize is possible, and when they do it can be quite a revelation. > > It don't mean nothin' if you can't use the validators. We tried recently, and > could not get them working in a non-ActiveRecord model. After exceeding our > time-box, we simply made the model into an ActiveRecord table, with no > records in the database yet. It's speculative coding, because we will need to > save the records for our next iteration. > > But, in theory, most of the validators have nothing to do with the > persistence itself, so the ActiveRecord maintainers could go decouple them... Couldn't you just write a #valid? method for the class, or something like that? If we're talking about non-AR models, they're probably not going to have #save or #update_attributes and so on, so you presumably wouldn't be depending on a save-time validation suite. In other words, what is the point in the life-cycle of the object that's analogous to saving an AR object, and can't you intervene at that point? David -- Rails training from David A. Black and Ruby Power and Light: * Advancing With Rails August 18-21 Edison, NJ * Co-taught by D.A. Black and Erik Kastner See http://www.rubypal.com for details and updates!