Hassan Schroeder wrote:
> I'm investigating moving from fixtures to generated data (using
> Machinist right now, though this question is probably generic to
> any generator) 

Good for you!  I believe that fixtures are so poorly designed that they 
should be removed from the Rails core.

> but I seem to be missing one essential point:
> 
> If I use a fixture, I can test that e.g.
> 
> -  an object will be valid with a valid owner (user) id
> -  an object can't be valid with a nil owner id
> -  an object can't be valid with a non-existent/invalid owner id
> 
> because I know what owner ids exist (and thus which don't exist).
> 
> 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
* Create a User, store the ID, delete the User.  VoilĂ , invalid ID.

> 
> Or am I completely off-track in some way? TIA!
> 

I think you are.  validates_associated is silly and circularity-prone. 
You should be using foreign key constraints in the DB for this (the 
foreign_key_migrations and Foreigner plugins make this easy).  And you 
don't need to test that in your app.

> --
> Hassan Schroeder ------------------------ [email protected]
> twitter: @hassan
> 
> --
> 
> 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.

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.


Reply via email to