forked from fixin.me/fixin.me
Extend all test tasks to run against every configured test database
When database.yml defines more than one top-level key starting with "test",
every standard test task (rails test, rails test:models, rails test:system,
rails test:controllers, …) is automatically rewritten at load time to run
the full suite against each configured database in turn.
Single-database setups are completely unaffected — the wrapping code
activates only when test_configs.size > 1, so existing behaviour is
preserved by default.
Convention: test: is the required primary; test_<name>: adds an adapter:
test_sqlite:
adapter: sqlite3
database: db/fixinme_test.sqlite3
test_pg:
adapter: postgresql
...
Mechanism:
- lib/tasks/test_databases.rake loads after railties/testing.rake (which
defines all test tasks). For each task in the wrapped set it calls
Rake::Task[name].clear_actions and re-enhances with a block that loops
over DB configs, writing a temporary database.yml per database and
running "rails <task_name>" as a subprocess with RAILS_DATABASE_YML set.
- config/application.rb(.dist): reads RAILS_DATABASE_YML and overrides
Rails' database config path before initialisation — no monkey-patching
of the test runner required.
- Adapter gem availability is checked before each run; missing adapters are
skipped with a hint on which bundle group to enable.
- A formatted summary (✓/✗ per database) is printed; exits non-zero on
any failure.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -48,3 +48,24 @@ production:
|
||||
#test:
|
||||
# <<: *default
|
||||
# database: fixinme_test
|
||||
|
||||
# Multi-database testing
|
||||
# ----------------------
|
||||
# Any key starting with "test" is treated as a test database.
|
||||
# When more than one is present, EVERY test task (rails test, rails test:models,
|
||||
# rails test:system, …) automatically runs against all of them.
|
||||
#
|
||||
# The adapter gem must be available:
|
||||
# bundle config --local with "mysql sqlite" # mysql + sqlite
|
||||
# bundle config --local with "mysql pg" # mysql + postgresql
|
||||
#
|
||||
#test_sqlite:
|
||||
# adapter: sqlite3
|
||||
# database: db/fixinme_test.sqlite3
|
||||
#
|
||||
#test_pg:
|
||||
# adapter: postgresql
|
||||
# database: fixinme_test
|
||||
# username: fixinme
|
||||
# password: Some-password1%
|
||||
# host: localhost
|
||||
|
||||
Reference in New Issue
Block a user