Rspec-rails: Pending Migrations in Engines

Created on 4 Mar 2015  路  2Comments  路  Source: rspec/rspec-rails

Hi guys,

I'm getting some problems with my engine specs.
I've generated my engine through rails plugin new name --mountable --dummy-path=spec/dummy command

I've also ran the default rspec generator, rails g rspec:install, but when i create my migrations, run rake db:migrate, and run rspec in my engine context, i'm always getting "Migrations are pending" in test environment.

Someone faced this problem?

Engine

Most helpful comment

Similar issue here.

@igorbelo does your engine copy the migrations into the dummy app, or do you monkeypatch something so they get recognized?

In my case, I rely on the rake rake xxxx:install:migrations as described in the rails guide to have the migrations copied into spec/dummy/db/migrate.

However, what I noticed is that current active record looks for the migrations in db/migrate of the engine, rather than the dummy app (see here).

I am not sure what the best practice would be now?

Override the migration_paths so the engine migrations are ignored and the ones in the dummy app are being read via rspec / spec_helper, or should the engine hook into rails and add the migration paths so no copying of migrations is needed anymore? (E.g as described here)

For now I just have this in the spec_helper, which solves my problem: ActiveRecord::Migrator.migrations_paths = 'spec/dummy/db/migrate'

This issue seems to be more of a question on best practice for rails engines rather than an actual rspec issue, or am I missing something?

All 2 comments

Similar issue here.

@igorbelo does your engine copy the migrations into the dummy app, or do you monkeypatch something so they get recognized?

In my case, I rely on the rake rake xxxx:install:migrations as described in the rails guide to have the migrations copied into spec/dummy/db/migrate.

However, what I noticed is that current active record looks for the migrations in db/migrate of the engine, rather than the dummy app (see here).

I am not sure what the best practice would be now?

Override the migration_paths so the engine migrations are ignored and the ones in the dummy app are being read via rspec / spec_helper, or should the engine hook into rails and add the migration paths so no copying of migrations is needed anymore? (E.g as described here)

For now I just have this in the spec_helper, which solves my problem: ActiveRecord::Migrator.migrations_paths = 'spec/dummy/db/migrate'

This issue seems to be more of a question on best practice for rails engines rather than an actual rspec issue, or am I missing something?

Hello @effkay, thanks for the tip, by setting ActiveRecord::Migrator.migrations_paths my app worked fine!

Sorry for this issue, but i didn't find this solution in anywhere, and it really seemed a problem.

Thanks

Was this page helpful?
0 / 5 - 0 ratings