views:

122

answers:

2

So I have some data loading in migrations, for instance a default user is created when the users table is made, and certain user Roles are created (like foo_admin) are created when the foos table is made.

The problem is cucumber doesn't like this, since it does a schema load.

Can I either make cucumber just run the migrations instead, or is there a better practice for doing that type of thing? machinist is being used as the factory (no fixtures!)

A: 

I have run into similar problems, and traced it back to the dependencies in rake. My solution was to run the cucumber script directly without rake, but this can require a some configuration in Rails (with Merb it works out f the box). The other solution is to override the rake task to it depends on db:migrate rather then db:load_schema.

NB. I've have little experience with recent versions of rails there may also be something in the bin/cucumber script or env.rb file that loads the schema file.

John F. Miller
+1  A: 

Don't use migrations to load data. It's widely considered to be a bad practice as the data loads are not preserved when building schema.rb.

Load your data from a rake task or another method that you can hook into your env.rb file's begin blog

begin do
  Role.create :name=>"admin"
  `rake RAILS_ENV="test" db:load_data_for_testing `
end

Or something like that.

Brian Hogan