Class: DatabaseCleaner::ActiveRecord::Truncation

Inherits:
Object
  • Object
show all
Includes:
Base, Generic::Truncation
Defined in:
lib/database_cleaner/active_record/truncation.rb

Direct Known Subclasses

Deletion

Instance Attribute Summary

Attributes included from Base

#connection_hash

Instance Method Summary collapse

Methods included from Base

#connection_class, #db, #db=, exclusion_condition, #load_config, migration_table_name, #valid_config

Constructor Details

#initializeTruncation

Returns a new instance of Truncation.



237
238
239
240
241
242
# File 'lib/database_cleaner/active_record/truncation.rb', line 237

def initialize(*)
  super
  if !@reset_ids.nil?
    DatabaseCleaner.deprecate "The `:reset_ids` option for the ActiveRecord truncation strategy has no effect, and is deprecated. It will be removed in database_cleaner 2.0 with no replacement."
  end
end

Instance Method Details

#cleanObject



244
245
246
247
248
249
250
251
252
253
# File 'lib/database_cleaner/active_record/truncation.rb', line 244

def clean
  connection = connection_class.connection
  connection.disable_referential_integrity do
    if pre_count? && connection.respond_to?(:pre_count_truncate_tables)
      connection.pre_count_truncate_tables(tables_to_truncate(connection), {:reset_ids => reset_ids?})
    else
      connection.truncate_tables(tables_to_truncate(connection))
    end
  end
end