Forum: Ruby on Rails test fixtures order

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.
5f0ca314f85e433454e19e1822cc8713?d=identicon&s=25 Rob Brit (robbrit)
on 2008-10-20 19:59
Hello, I'm trying to get my Rails test suite to load fixtures in a
certain order, but I'm coming across a really strange problem.

I have two tables and a join table. Instead of creating the entries for
the join table manually, I just go

Table1.each do |t1|
  Table2.each do |t2|
    ...

to create the fields. This only works if Table1 and Table2 are loaded
before the join table is loaded.

Now, when I go "rake test", it fails on the unit tests that are
dependent on the join table having values, but the functional tests that
are dependent on them succeed. However, if I go "rake test:functionals",
they fail. It seems like the first test suite that gets loaded does not
create these entries.

Anybody know why this might happen?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-20 22:16
(Received via mailing list)
On Oct 20, 6:59 pm, Rob Brit <rails-mailing-l...@andreas-s.net> wrote:
> Hello, I'm trying to get my Rails test suite to load fixtures in a
> certain order, but I'm coming across a really strange problem.
>
> I have two tables and a join table. Instead of creating the entries for
> the join table manually, I just go
>
> Table1.each do |t1|
>   Table2.each do |t2|
>     ...
>
Where is this code been run ? (and to be quite blunt - why?)

Fred
5f0ca314f85e433454e19e1822cc8713?d=identicon&s=25 Rob Brit (robbrit)
on 2008-10-20 22:21
> Where is this code been run ?

It's being run in the join table's fixture.

> (and to be quite blunt - why?)

Because there's a lot of test data in the other two tables, and typing
it out by hand would be big waste of time. Normally the data in the join
table is generated by after_save, but since that isn't called when
fixtures are loaded I have to do it this way.
5f0ca314f85e433454e19e1822cc8713?d=identicon&s=25 Rob Brit (robbrit)
on 2008-10-20 22:39
Actually never mind, I found another solution.
8a0c6bd8d6c075133944138e2fea8d2c?d=identicon&s=25 ant (Guest)
on 2008-10-22 07:24
(Received via mailing list)
Great.... what was your other solution?!
5f0ca314f85e433454e19e1822cc8713?d=identicon&s=25 Rob Brit (robbrit)
on 2008-10-22 16:23
I just wrote a script for runner that just loaded in all the original
fixtures I had for the two non-join tables, and based on what was in
those generated a YAML file for the join table and reloaded the DB.
This topic is locked and can not be replied to.