forked from fixin.me/fixin.me
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>
72 lines
2.2 KiB
Plaintext
72 lines
2.2 KiB
Plaintext
# If you don't want to store sensitive information, like your database password,
|
|
# in your source code, provide the password or a full connection URL as an
|
|
# environment variable when you boot the app. For example:
|
|
#
|
|
# DATABASE_PASSWORD="Some-password1%"
|
|
#
|
|
# or
|
|
#
|
|
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
|
|
#
|
|
# If the connection URL is provided in the special DATABASE_URL environment
|
|
# variable, Rails will automatically merge its configuration values on top of
|
|
# the values provided in this file. Alternatively, you can specify a connection
|
|
# URL environment variable explicitly:
|
|
#
|
|
# production:
|
|
# url: <%= ENV["MY_APP_DATABASE_URL"] %>
|
|
#
|
|
# You can specify password environment variable in a similar way:
|
|
#
|
|
# production:
|
|
# password: <%= ENV["DATABASE_PASSWORD"] %>
|
|
#
|
|
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
|
|
# for a full overview on how database connection configuration can be specified.
|
|
default: &default
|
|
adapter: mysql2
|
|
encoding: utf8mb4
|
|
collation: utf8mb4_0900_as_ci
|
|
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
|
username: fixinme
|
|
password: Some-password1%
|
|
socket: /run/mysqld/mysqld.sock
|
|
|
|
production:
|
|
<<: *default
|
|
database: fixinme
|
|
|
|
# Unless you're planning on developing the application, you can skip
|
|
# configurations for development and test databases altogether.
|
|
#development:
|
|
# <<: *default
|
|
# database: fixinme_dev
|
|
|
|
# Warning: The database defined as "test" will be erased and
|
|
# re-generated from your development database when you run "rake".
|
|
# Do not set this db to the same as development or 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
|