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.
8aa68df8d14eff5681c8e87a073e8cca?d=identicon&s=25 Gitte Wange (Guest)
on 2006-01-08 15: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 Wange
5085ba37ba624a788e04a842cd09bd6e?d=identicon&s=25 Jens-Christian Fischer (Guest)
on 2006-01-09 15: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.