9

I just joined a project developing a rails engine, that also has a dummy app for testing.

foo/
foo/spec/dummy/

There are identical migrations in

foo/db/migrate/
foo/spec/dummy/db/migrate/

If I rake db:migrate from the dummy app, all is well. If I do the same from the engine (current directory = foo) I get an error about multiple migrations with the same name.

Q1) Are the Rakefiles borked? (should db:migrate recurse down to the dummy app?)

Q2) Should the migrations only be in one directory? If so, which one?

We are using Rails 3.2.9, ruby 1.9.3p194.

zjaquish
  • 271
  • 2
  • 8

2 Answers2

9

Question 1
The Rakefile should have an entry to account for the spec/dummy app. For example,

Bundler::GemHelper.install_tasks
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'

Here's more detailed example rakefile, https://github.com/twinge/questionnaire_engine/blob/engine2/Rakefile

Question 2
IMO, the migrations should only exist on the foo/db/migrate folder, and not the foo/spec/dummy/db/migrate. In fact, I don't version control the dummy's db/migrate or the db/schema.

Why? I use the dummy app the make sure a full on install of my engine works 100%. Therefore, if I version controlled the foo/spec/dummy db state, I would be testing as if there was a previous install.

Example Engine
https://github.com/twinge/questionnaire_engine/tree/engine2

westonplatter
  • 1,475
  • 2
  • 19
  • 30
0

For testing the dummy app, you can run your engine migrations for the test ENV using the following:

RAILS_ENV=test rake db:migrate
Bonnie Simon
  • 51
  • 1
  • 7