Module: DatabaseCleaner::ActiveRecord::ConnectionWrapper::PostgreSQLAdapter

Defined in:
lib/database_cleaner/active_record/truncation.rb

Instance Method Summary collapse

Instance Method Details

#database_cleaner_table_cacheObject



203
204
205
206
207
208
209
210
# File 'lib/database_cleaner/active_record/truncation.rb', line 203

def database_cleaner_table_cache
  # AR returns a list of tables without schema but then returns a
  # migrations table with the schema. There are other problems, too,
  # with using the base list. If a table exists in multiple schemas
  # within the search path, truncation without the schema name could
  # result in confusing, if not unexpected results.
  @database_cleaner_tables ||= tables_with_schema
end

#database_tablesObject



186
187
188
# File 'lib/database_cleaner/active_record/truncation.rb', line 186

def database_tables
  tables_with_schema
end

#pre_count_tables(tables) ⇒ Object



199
200
201
# File 'lib/database_cleaner/active_record/truncation.rb', line 199

def pre_count_tables(tables)
  tables.select { |table| has_been_used?(table) }
end

#pre_count_truncate_tables(tables) ⇒ Object



195
196
197
# File 'lib/database_cleaner/active_record/truncation.rb', line 195

def pre_count_truncate_tables(tables)
  truncate_tables(pre_count_tables(tables))
end

#truncate_tables(table_names) ⇒ Object



190
191
192
193
# File 'lib/database_cleaner/active_record/truncation.rb', line 190

def truncate_tables(table_names)
  return if table_names.nil? || table_names.empty?
  execute("TRUNCATE TABLE #{table_names.map{|name| quote_table_name(name)}.join(', ')} RESTART IDENTITY CASCADE;")
end