Last active
January 9, 2017 15:46
-
-
Save bbozo/7a46abc4c04a9541cf7c4934d89182c1 to your computer and use it in GitHub Desktop.
minitest-parallel_fork setup for ActiveRecord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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