Sha256: 1c41255059fdfe72ff68391bb072fef957789f19dfb63e2bb9a4ad7f32247396

Contents?: true

Size: 802 Bytes

Versions: 1

Compression:

Stored size: 802 Bytes

Contents

module NdrDevSupport
  module IntegrationTesting
    # 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: https://gist.github.com/josevalim/470808
    #
    module ConnectionSharing
      def self.prepended(base)
        base.mattr_accessor :shared_connection

        # Get a connection, and make it shareable:
        base.shared_connection = base.connection

        base.singleton_class.prepend(ClassMethods)
      end

      module ClassMethods
        def connection
          shared_connection || retrieve_connection
        end
      end
    end
  end
end

ActiveRecord::Base.prepend(NdrDevSupport::IntegrationTesting::ConnectionSharing)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ndr_dev_support-1.2.0 lib/ndr_dev_support/integration_testing/connection_sharing.rb