forked from fixin.me/fixin.me
Extend all test tasks to run against every configured test db (WIP)
This commit is contained in:
42
lib/core_ext/test_multiple_adapters.rb
Normal file
42
lib/core_ext/test_multiple_adapters.rb
Normal 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
|
||||
Reference in New Issue
Block a user