Skip to content

Instantly share code, notes, and snippets.

@almostwhitehat
Forked from josevalim/shared_connection.rb
Last active September 17, 2015 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almostwhitehat/ab790ffb0340f88947b3 to your computer and use it in GitHub Desktop.
Save almostwhitehat/ab790ffb0340f88947b3 to your computer and use it in GitHub Desktop.
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment