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



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

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



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

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

#database_tablesObject



98
99
100
# File 'lib/database_cleaner/active_record/truncation.rb', line 98

def database_tables
  tables
end

#truncate_table(table_name) ⇒ Object



102
103
104
105
106
# File 'lib/database_cleaner/active_record/truncation.rb', line 102

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, opts) ⇒ Object



108
109
110
# File 'lib/database_cleaner/active_record/truncation.rb', line 108

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