Adds `bundle exec rails test:all_databases` which runs the full test
suite against every test database configured in database.yml in a single
command.
Convention: any top-level key starting with "test" that contains a Hash
is a test database. `test:` is the required primary; `test_<name>:` blocks
are optional additional adapters (e.g. test_sqlite, test_pg).
For each configured database the task:
1. Checks the required adapter gem is available (skips with warning if not)
2. Runs `rails db:test:prepare` to create and migrate the database
3. Runs `rails test` and records pass/fail
4. Prints a summary and exits non-zero if any database failed
Mechanism: a RAILS_DATABASE_YML env var points each subprocess to a
temporary database.yml that contains only the current test config.
config/application.rb(.dist) reads this var and overrides Rails'
database config path before initialisation, so no monkey-patching of
the test runner is required.
config/database.yml.dist is updated with documented examples for SQLite
and PostgreSQL additional test databases.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 10:48:53 +00:00
3 changed files with 106 additions and 144 deletions
# Rewrite every standard test task to run against all configured databases.
# This file loads after railties/testing.rake, so all tasks already exist.
# Single-database setups are completely unaffected.
ifMultiDbTests.test_configs.size>1
MultiDbTests::WRAPPED_TASKS.eachdo|task_name|
nextunlessRake::Task.task_defined?(task_name)
Rake::Task[task_name].clear_actions
Rake::Task[task_name].enhancedo
MultiDbTests.run(task_name)
end
end
ADAPTER_GROUPS.fetch(adapter,adapter)
end
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.