Files
fixin.me/config/application.rb.dist
barbie-bot 3e0f27b357 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>
2026-04-05 11:07:30 +00:00

63 lines
2.5 KiB
Plaintext

require_relative "boot"
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
# require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
# require "action_cable/engine"
require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module FixinMe
class Application < Rails::Application
# Allow RAILS_DATABASE_YML to override the database config file path.
# Used by the multi-database test runner (lib/tasks/test_databases.rake).
config.paths['config/database'] = [ENV['RAILS_DATABASE_YML']] if ENV['RAILS_DATABASE_YML']
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0
# Autoload lib/, required e.g. for core library extensions.
# https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#config-autoload-lib-ignore.
config.autoload_lib(ignore: %w(assets tasks))
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
config.action_dispatch.rescue_responses['ApplicationController::AccessForbidden'] = :forbidden
config.action_dispatch.rescue_responses['ApplicationController::ParameterInvalid'] = :unprocessable_entity
# SETUP: Below settings need to be updated on a per-installation basis.
#
# URL to use in sent e-mails.
config.action_mailer.default_url_options = {host: 'localhost', :protocol => 'https'}
# https://guides.rubyonrails.org/configuring.html#config-action-mailer-delivery-method
config.action_mailer.delivery_method = :sendmail
# List of hosts this app is available at.
# https://guides.rubyonrails.org/configuring.html#actiondispatch-hostauthorization
config.hosts += ['localhost', 'example.com', IPAddr.new('1.2.3.4/32')]
# Email address of admin account
config.admin = 'admin@localhost'
# Sender address of account registration-related messages
Devise.mailer_sender = 'noreply@localhost'
end
end