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



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

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



80
81
82
# File 'lib/database_cleaner/active_record/truncation.rb', line 80

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

#database_tablesObject



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

def database_tables
  tables
end

#truncate_table(table_name) ⇒ Object



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

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



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

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