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



211
212
213
214
215
216
217
218
# File 'lib/database_cleaner/active_record/truncation.rb', line 211

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



193
194
195
# File 'lib/database_cleaner/active_record/truncation.rb', line 193

def database_tables
  tables_with_schema
end

#pre_count_tables(tables) ⇒ Object



207
208
209
# File 'lib/database_cleaner/active_record/truncation.rb', line 207

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

#pre_count_truncate_tables(tables) ⇒ Object



203
204
205
# File 'lib/database_cleaner/active_record/truncation.rb', line 203

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

#truncate_tables(table_names, opts) ⇒ Object



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

def truncate_tables(table_names, opts)
  return if table_names.nil? || table_names.empty?

  execute("TRUNCATE TABLE #{table_names.map{|name| quote_table_name(name)}.join(', ')} RESTART IDENTITY #{opts[:truncate_option]};")
end