0

Using ActiveSupport::TestCase. I think that's the old Test::Unit.

I have several tables that represent enumerated values. These never change and I would like to use their data in class scope for activerecord finders.

This causes a problem with tests because model classes load before fixtures and fixtures are rolled back between tests. I can't copy the enum tables into a fixture because the data will not yet be loaded when models load.

Is there a way to bring the test database to an initial state before models load and before the fixture transaction begins?

Samuel Danielson
  • 5,231
  • 3
  • 35
  • 37

2 Answers2

0

How about defining a setup method for your tests?

Or seeding the database using db/seeds.rb?

TK-421
  • 10,598
  • 3
  • 38
  • 34
  • db/seeds.rb doesn't seem to load when tests are run. If I load it manually it gets deleted when tests start. Where can I hook into the test setup to seed the db? The normal setup that runs before each test won't work. It needs to run once before all tests. – Samuel Danielson Jan 26 '11 at 17:51
  • 2
    For seeding, see the discussion here: http://stackoverflow.com/questions/1898782/prevent-rails-test-from-deleting-seed-data. In particular check out the comments. – TK-421 Jan 26 '11 at 18:04
0

If they never ever change you could put the create statements directly into your migrations so they are created when the tables are rebuilt - seems a bit messy to be honest though but should work.

John Beynon
  • 37,398
  • 8
  • 88
  • 97
  • 1
    Migrations aren't run to start a test run. The test schema is created from db/schema.rb, a generated file. Come to think about it, I have the same problem with db views in tests since views aren't cloned to db/schema.rb. If I could set what goes into db/schema.rb I could solve both problems, but perhaps there is a better way. – Samuel Danielson Jan 26 '11 at 17:55