The problem you are having is that the fixtures that you have to
specify all the fixtures that you use in the flower_test are how you
have to use the fixtures in the others. THis is because, as you said,
there are foreign keys that affect the entire database.
What I wold suggest is just adding "fixtures :worlds, :trees,
:flowers" to /test/test_helper.rb in the Test::Unit::TestCase class
extention
Cheers,
Dan
On 7/26/05, Jean Helou
<jean.helou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> * Introduction
> I am trying to reconcile my test suite and the foreign keys
> constraints in my database. I have been able to get each individual
> testcase to work when run directly by changing the ordre of the
> fixtures so they are inserted and deleted in the right order.
>
> However, I am unable to make the testsuite run correctly when executed
> from the rake task.
> I was able to pinpoint the problem but I am not sure how to solve it,
> I tried google, the wiki and the list but couldn''t find a
satisfying
> answer. I provide a schema (mysql), some fixtures and unit tests which
> allow to reproduce the problem.
>
> * The problem:
> - Foreign key constraints without delete cascade, won''t allow you
to
> remove a row whose id is referenced by another table in the database.
> - The reload of the fixtures for unit tests consists of a DELETE from
> `Table`; followed by an INSERT for each entry in the fixture.
>
> - The unit tests are executed in alphabetical order and each test
> attempts to reload the fixtures into the database. However, the tests
> only reload the fixtures _they_ need.
>
> Therefore, if you have a table named flowers which depends on the
> table worlds. The test for flowers will be executed before the test
> for worlds, and when the test for world will execute, it will attempt
> to DELETE from `worlds` which (of course) will fail.
>
> * The solutions ?
> I suppose I could clear the flowers table in the teardown of the
> flowers tests, but I''d rather not as I think it would break
> transactionnal fixtures. Is there a way to specify the ordering or
> even better, to get the fixtures to behave as advertised :
>
> http://api.rubyonrails.com/classes/Fixtures.html
>
> (By adding a "fixtures" method to the test case and passing it a
list
> of symbols (only one is shown here tho), we trigger the testing
> environment to automatically load the appropriate fixtures into the
> database before each test. To ensure consistent data, the environment
> deletes the fixtures before running the load.)
>
> Jean
> PS: for your convenience I also provide all the files in a zip archive
> with the correct paths. simply unzip in a new rails install and run
> the (mysql) schema against an empty db..
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
>