Sha256: d7dc5183dff630c0ea7c05be4c3d03d1461376d2d323a1261bd563c985353f9d

Contents?: true

Size: 913 Bytes

Versions: 13

Compression:

Stored size: 913 Bytes

Contents

require Pathname.new(__FILE__).parent.to_s + '/shared_connection_db_helpers'

module Marty; module RSpec; module SharedConnection
  @@classes_to_exclude_from_shared = ['Marty::Log']
  mattr_accessor :classes_to_exclude_from_shared

  EXCL_LAMBDA = lambda { classes_to_exclude_from_shared }.freeze

  class ActiveRecord::Base
    mattr_accessor :shared_connection
    class << self
      alias_method :orig_connection, :connection
    end
    def self.clear_connection
      @@shared_connection = nil
    end

    clear_connection

    def self.connection
      EXCL_LAMBDA.call.include?(model_name) ? orig_connection :
        @@shared_connection ||
        ConnectionPool::Wrapper.new(:size => 1) {retrieve_connection}
    end

    def self.reset_shared_connection
      @@shared_connection = ConnectionPool::Wrapper.
                              new(:size => 1) {retrieve_connection}
    end
  end
end end end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
marty-2.5.2 spec/support/shared_connection.rb
marty-2.5.1 spec/support/shared_connection.rb
marty-2.5.0 spec/support/shared_connection.rb
marty-2.4.9 spec/support/shared_connection.rb
marty-2.4.8 spec/support/shared_connection.rb
marty-2.4.7 spec/support/shared_connection.rb
marty-2.4.6 spec/support/shared_connection.rb
marty-2.4.5 spec/support/shared_connection.rb
marty-2.4.4 spec/support/shared_connection.rb
marty-2.4.3 spec/support/shared_connection.rb
marty-2.4.2 spec/support/shared_connection.rb
marty-2.4.1 spec/support/shared_connection.rb
marty-2.3.15 spec/support/shared_connection.rb