Search code examples
ruby-on-railsunit-testingfixtures

Rails unit testing doesn't load fixtures


rake test:units fails in my current application, because the needed data of the fixtures is missing.

If I'm loading the fixtures manually via rake db:fixtures:load RAILS_ENV=test the unit tests are working, but rake purges the test database.

My test_helper includes fixtures :all and my tests are inheriting from it - but the fixtures are simply not loading.

I'm kind of clueless at the moment and could really need some help!

I've tried a lot and I think it has to do with some environment settings or plugins used in this project. Does anyone know where to read about which files are loaded for the testing environment?


Solution

  • I finally found the problem, although the solutions is kind of hacky.

    One plugin is relying that there is some data in the database, at least one row. So what happened was:

    1. rake loads database schema
    2. rake tries to load environment
    3. environment includes plugin
    4. plugin loading fails because of missing at least one row
    5. no fixtures are loaded

    The hacky solution is: put the needed data directly into schema and not into a fixtures, because it's loaded to late.

    I'll search for a more convenient solution and will update this answer if I found one.