Forum: Ruby on Rails Using many-to-many relations in tests

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Gitte W. (Guest)
on 2006-01-08 16:57
(Received via mailing list)
Hello,

I have some many-to-many relations, I would like to use in my tests. But
I'm not sure what I should put in the fixtures for it?
How do I add those relations in the testing environment?

Greetings,
Gitte W.
Jens-Christian F. (Guest)
on 2006-01-09 16:29
(Received via mailing list)
> I have some many-to-many relations, I would like to use in my
> tests. But I'm not sure what I should put in the fixtures for it?
> How do I add those relations in the testing environment?

you need to create fixtures for your join table as well:

if you have two models (Foo and Bar) and a bar_foos table for the join:

bar_foos.yml

first:
   foo_id: 1
   bar_id: 1
second:
   foo_id: 1
   bar_id: 2

etc.

in your unit tests, load all fixtures:

   fixtures :foos, :bars, :bar_foos


hth jc
This topic is locked and can not be replied to.