Module: DatabaseCleaner::ActiveRecord::ConnectionWrapper::AbstractAdapter

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

Instance Method Summary collapse

Instance Method Details

#database_cleaner_table_cacheObject



90
91
92
93
# File 'lib/database_cleaner/active_record/truncation.rb', line 90

def database_cleaner_table_cache
  # the adapters don't do caching (#130) but we make the assumption that the list stays the same in tests
  @database_cleaner_tables ||= database_tables
end

#database_cleaner_view_cacheObject

used to be called views but that can clash with gems like schema_plus this gem is not meant to be exposing such an extra interface any way



86
87
88
# File 'lib/database_cleaner/active_record/truncation.rb', line 86

def database_cleaner_view_cache
  @views ||= select_values("select table_name from information_schema.views where table_schema = '#{current_database}'") rescue []
end

#database_tablesObject



95
96
97
# File 'lib/database_cleaner/active_record/truncation.rb', line 95

def database_tables
  tables
end

#truncate_table(table_name) ⇒ Object



99
100
101
102
103
# File 'lib/database_cleaner/active_record/truncation.rb', line 99

def truncate_table(table_name)
  execute("TRUNCATE TABLE #{quote_table_name(table_name)}")
rescue ::ActiveRecord::StatementInvalid
  execute("DELETE FROM #{quote_table_name(table_name)}")
end

#truncate_tables(tables) ⇒ Object



105
106
107
# File 'lib/database_cleaner/active_record/truncation.rb', line 105

def truncate_tables(tables)
  tables.each { |t| truncate_table(t) }
end