seeds.rb and rake test tasks

We've started using seeds.rb to populate some low-level required data into our database, but we're having some issues with this data getting removed and not re-entered while running the tests.

Is seeding part of the testing lifecycle or do we have to replicate the seed data in the fixtures as well?

My guess is that you'd need to add this to your test setup. By default, everything is rolled back from your test database after every test.

def setup `rake db:seed` end

With backticks it will run the shell process, and should wait for it to finish before proceeding.

Nothing comes up when I search the api docs for 'seed', so for now it may just be in rake. It may take some digging in the source to find out whether you can seed the database directly from Rails. Or there may be a gem that can help.

I'm a bit new to the Rails stuff, but what's the expected convention for running the tests.

I've been doing - rake db:setup RAILS_ENV=test rake test:unit RAILS_ENV=test

Just to make sure I'm not fighting the conventions.

If you run

rake -T test

in your project directory, you can see all your available test tasks. Two helpful ones are:

rake db:test:clone rake db:test:load

Oh, another option for your original problem is to turn off db rollbacks in your test environment. Unfortunately I can't remember the option for doing that. Just keep in mind that you'll want to manually clear out the database occasionally or you may see your tests slow down.

I'd recommend installing Autotest. (Also give serious thought to RSpec.)

Seriously. This is super helpful. Also, you may want to look into something like factory_girl. If your tests aren't really coupled to your seed data, they just need dummy records for your models, this may be a better way to go. That way your tests don't assume particular records in your database.

Unfortunately, it's not the tests that depend upon the data, it's the code itself. The seed data is reference data, which is basically just one step above an enumeration.