Class: DatabaseCleaner::ActiveRecord::Base

Inherits:
Strategy
  • Object
show all
Defined in:
lib/database_cleaner/active_record/base.rb

Direct Known Subclasses

Transaction, Truncation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connection_hashObject

Returns the value of attribute connection_hash.



39
40
41
# File 'lib/database_cleaner/active_record/base.rb', line 39

def connection_hash
  @connection_hash
end

Class Method Details

.exclusion_condition(column_name) ⇒ Object



27
28
29
30
31
32
# File 'lib/database_cleaner/active_record/base.rb', line 27

def self.exclusion_condition(column_name)
  <<~SQL
    #{column_name} <> '#{DatabaseCleaner::ActiveRecord::Base.migration_table_name}'
      AND #{column_name} <> '#{::ActiveRecord::Base.}'
  SQL
end

.migration_table_nameObject



17
18
19
20
21
22
23
24
25
# File 'lib/database_cleaner/active_record/base.rb', line 17

def self.migration_table_name
  if ::ActiveRecord::Base.connection_pool.respond_to?(:schema_migration) # Rails >= 7.2
    ::ActiveRecord::Base.connection_pool.schema_migration.table_name
  elsif ::ActiveRecord::Base.connection.respond_to?(:schema_migration) # Rails >= 6.0
    ::ActiveRecord::Base.connection.schema_migration.table_name
  else
    ::ActiveRecord::SchemaMigration.table_name
  end
end

Instance Method Details

#connection_classObject



41
42
43
44
45
46
47
48
49
# File 'lib/database_cleaner/active_record/base.rb', line 41

def connection_class
  @connection_class ||= if db && !db.is_a?(Symbol)
                          db
                        elsif connection_hash
                          (lookup_from_connection_pool rescue nil) || establish_connection
                        else
                          ::ActiveRecord::Base
                        end
end

#db=Object



34
35
36
37
# File 'lib/database_cleaner/active_record/base.rb', line 34

def db=(*)
  super
  load_config
end