Extend all test tasks to run against every configured test db (WIP)

This commit is contained in:
2026-04-13 00:39:03 +02:00
parent 376640cfd7
commit dd9572689a
6 changed files with 67 additions and 4 deletions

View File

@@ -0,0 +1,42 @@
require "byebug"
module CoreExt
module TestMultipleAdapters
def perform(...)
#require APP_PATH
$LOAD_PATH << Rails::Command.root.join("test").to_s
require "test_helper"
Rails.application.config.database_configuration.each_pair do |name, config|
next unless name.start_with?('test_')
puts config['adapter']
ENV['DATABASE_URL'] = dbconfig_to_url(config)
byebug
super
end
end
alias_method :test, :perform
private
def dbconfig_to_url(cfg)
return cfg['url'] if cfg.has_key?("url")
config = cfg.transform_values { |v| URI.encode_www_form_component(v) }
username, password = config.delete('username'), config.delete('password')
auth = username ? "#{username}:#{password}" : ''
host, port = config.delete('host'), config.delete('port')
server = port ? "#{host}:#{port}" : host
url = "#{config.delete('adapter')}:"
url += "//#{auth}@#{server}" if auth || server
url += "/#{config.delete('database')}"
url += "?#{config.map { |k,v| "#{k}=#{v}" }.join('&')}" unless config.empty?
end
end
end
#require "rails/commands/test/test_command"
#Rails::Command::TestCommand.prepend CoreExt::TestMultipleAdapters