Module: NdrDevSupport::IntegrationTesting::ConnectionSharing

Defined in:
lib/ndr_dev_support/integration_testing/connection_sharing.rb

Overview

              !! Caution - please read carefully !!

This approach to connection sharing is known to be susceptible
to race conditions. Anecdotally, we've managed to avoid this
being a problem with Oracle because of the use of the confuration

  ActiveRecord::Base.connection.raw_connection.non_blocking = false

which prevents the C extension in the adapter being able to run
non-blocking code (i.e. outside of the control of the global interpretter
lock). On Postgres, we haven't employed an equivalent workaround.

For a more resilient alternative, please use the 'database_cleaner'
gem (see README for details).

Capybara starts another rails application in a new thread to test against. For transactional fixtures to work, we need to share the database connection between threads.

Derived from: gist.github.com/josevalim/470808

Modified to support multiple connection pools

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



31
32
33
34
35
36
# File 'lib/ndr_dev_support/integration_testing/connection_sharing.rb', line 31

def self.prepended(base)
  base.mattr_accessor :shared_connections
  base.shared_connections = {}

  base.singleton_class.prepend(ClassMethods)
end