rails/rails — pull request #17739 by senny (2014-11-24 11:26:03+00:00)
Title: bring back `db:test:prepare`.

This reverts deprecations added in #13528.
The task is brought back for two reasons:
1. Give plugins a way to hook into the test database initialization process
2. Give the user a way to force a test database synchronization

While `test:prepare` is still a dependency of every test task, `db:test:prepare`
no longer hooks into it. This means that `test:prepare` runs before the schema
is synchronized. Plugins, which insert data can now hook into `db:test:prepare`.

The automatic schema maintenance can't detect when a migration is rolled-back,
modified and reapplied. In this case the user has to fall back to `db:test:prepare`
to force the synchronization to happen.

#### Context

Since automatic schema maintenance has been shipped with `4.1` we need a backportable solution. This patch tries to address parts of the problems reported in #17171, #17170, #15787

We started to move away from `rake` as the primary mechanism to setup the testing environment. Some parts (like existing hooks) did not get the necessary attention. For `5.0` we can finish that transition and provide a sensible upgrade path for plugins.

#### Discussion

This patch brings the following shortcomings:
* It doesn't restore the hooks as they were. `test:prepare` still runs before the schema was maintained. Plugins that rely on the schema need to switch to the `db:test:prepare` hook.
* `maintain_test_schema!` now shells out to `bin/rake` to synchronize the schema. This adds the cost of loading the Rails environment twice when changes are detected.
* We already started issuing deprecations in `4.1.` this might come as an unexpected change.

#### TODO

- [ ] Write tests
- [ ] Adjust documentation
- [ ] Add CHANGELOG entry