Sha256: e93d219d061d1708808e4555fe5beff5ad423bc7c45befcb6a684b712dddf468

Contents?: true

Size: 1.19 KB

Versions: 17

Compression:

Stored size: 1.19 KB

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
      # Workaround to fix a bug in Rails 6 with shared connections
      # https://github.com/rails/rails/issues/36757
      model_name_str = if name == 'primary::SchemaMigration'
                         name
                       else
                         model_name
                       end

      EXCL_LAMBDA.call.include?(model_name_str) ? 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

17 entries across 17 versions & 1 rubygems

Version Path
marty-14.3.0 spec/support/shared_connection.rb
marty-14.0.0 spec/support/shared_connection.rb
marty-13.0.2 spec/support/shared_connection.rb
marty-11.0.0 spec/support/shared_connection.rb
marty-10.0.3 spec/support/shared_connection.rb
marty-10.0.2 spec/support/shared_connection.rb
marty-10.0.0 spec/support/shared_connection.rb
marty-9.5.1 spec/support/shared_connection.rb
marty-9.5.0 spec/support/shared_connection.rb
marty-9.3.3 spec/support/shared_connection.rb
marty-9.3.2 spec/support/shared_connection.rb
marty-9.3.0 spec/support/shared_connection.rb
marty-8.5.0 spec/support/shared_connection.rb
marty-8.4.1 spec/support/shared_connection.rb
marty-8.3.1 spec/support/shared_connection.rb
marty-8.2.0 spec/support/shared_connection.rb
marty-8.0.0 spec/support/shared_connection.rb