Skip to content

Instantly share code, notes, and snippets.

@bbozo
Last active January 9, 2017 15:46
Show Gist options
  • Save bbozo/7a46abc4c04a9541cf7c4934d89182c1 to your computer and use it in GitHub Desktop.
Save bbozo/7a46abc4c04a9541cf7c4934d89182c1 to your computer and use it in GitHub Desktop.
minitest-parallel_fork setup for ActiveRecord
Minitest.before_parallel_fork do
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
Minitest.after_parallel_fork do |i|
if defined?(ActiveRecord::Base)
db_config = Rails.application.config.database_configuration[Rails.env].clone
db_config['database'] += (i+1).to_s
ActiveRecord::Base.establish_connection(db_config)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment