Hassan Schroeder wrote: > On Mon, Dec 28, 2009 at 10:55 AM, Marnen Laibow-Koser > <[email protected]> wrote: > >>> If I use a generator to create test objects and owners, I have no >>> idea what owner ids have been created, so how can I specify an >>> invalid one for test purposes? >> >> You probably don't need to. �But a couple of ideas come to mind: >> * User.max(:id) + 10 > > That didn't work but got me thinking in a workable direction, thanks.
Why didn't it work? That should be foolproof, unless I screwed up the syntax. > >> ... validates_associated is silly and circularity-prone. >> You should be using foreign key constraints in the DB for this > > Well, I'll take that under advisement :-) but I would prefer to have the > business logic in the app, and tested. Data integrity checking isn't business logic in the usual sense -- and it really is the job of the database. > Even if (as in this case) it's > not > actually TDD/BDD because I'm adding tests to someone else's code, > the test suite now reflects intent -- better than the usual (which is to > say no) documentation thereof. Then have the validations as a backup, but remember that they're only a backup. Integrity constraints in the DB are not optional for a well-designed app. And I repeat my suggestion to get rid of validates_associated. It makes extra queries and introduces possible circularities to do something that the DB already does better. It's reinventing a square wheel in the wrong place. If you need documentation, add a comment -- but I tend to think that the belongs_to statement will reveal enough intention. You're falling into the common Rails trap of not respecting the database's intelligence. It's not dumb, and it should not be treated as if it were. > > Thanks, > -- > Hassan Schroeder ------------------------ [email protected] > twitter: @hassan 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.

