Module: DatabaseCleaner

Defined in:
lib/database_cleaner/base.rb,
lib/database_cleaner/generic/base.rb,
lib/database_cleaner/mongoid/base.rb,
lib/database_cleaner/configuration.rb,
lib/database_cleaner/null_strategy.rb,
lib/database_cleaner/data_mapper/base.rb,
lib/database_cleaner/mongo/truncation.rb,
lib/database_cleaner/couch_potato/base.rb,
lib/database_cleaner/mongo_mapper/base.rb,
lib/database_cleaner/active_record/base.rb,
lib/database_cleaner/generic/truncation.rb,
lib/database_cleaner/mongoid/truncation.rb,
lib/database_cleaner/data_mapper/truncation.rb,
lib/database_cleaner/couch_potato/truncation.rb,
lib/database_cleaner/mongo_mapper/truncation.rb

Defined Under Namespace

Modules: ActiveRecord, CouchPotato, DataMapper, Generic, Mongo, MongoMapper, Mongoid Classes: Base, NoORMDetected, NullStrategy, UnknownStrategySpecified

Class Method Summary collapse

Class Method Details

.[](orm, opts = {}) ⇒ Object

Raises:



9
10
11
12
13
14
15
# File 'lib/database_cleaner/configuration.rb', line 9

def [](orm,opts = {})
  raise NoORMDetected if orm.nil?
  @connections ||= []
  cleaner = DatabaseCleaner::Base.new(orm,opts)
  connections.push cleaner
  cleaner
end

.app_rootObject



21
22
23
# File 'lib/database_cleaner/configuration.rb', line 21

def app_root
  @app_root || Dir.pwd
end

.app_root=(desired_root) ⇒ Object



17
18
19
# File 'lib/database_cleaner/configuration.rb', line 17

def app_root=(desired_root)
  @app_root = desired_root
end

.cleanObject Also known as: clean!



55
56
57
# File 'lib/database_cleaner/configuration.rb', line 55

def clean
  self.connections.each { |connection| connection.clean }
end

.clean_with(*args) ⇒ Object Also known as: clean_with!



61
62
63
# File 'lib/database_cleaner/configuration.rb', line 61

def clean_with(*args)
  self.connections.each { |connection| connection.clean_with(*args) }
end

.connectionsObject



25
26
27
# File 'lib/database_cleaner/configuration.rb', line 25

def connections
  @connections ||= [::DatabaseCleaner::Base.new]
end

.loggerObject



33
34
35
36
37
38
39
# File 'lib/database_cleaner/configuration.rb', line 33

def logger
  return @logger if @logger
  
  @logger = Logger.new(STDOUT)
  @logger.level = Logger::ERROR
  @logger
end

.logger=(log_source) ⇒ Object



29
30
31
# File 'lib/database_cleaner/configuration.rb', line 29

def logger=(log_source)
  @logger = log_source
end

.orm=(orm) ⇒ Object



46
47
48
49
# File 'lib/database_cleaner/configuration.rb', line 46

def orm=(orm)
  self.connections.each { |connect| connect.orm = orm }
  remove_duplicates
end

.orm_module(symbol) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/database_cleaner/configuration.rb', line 75

def orm_module(symbol)
  case symbol
    when :active_record
      DatabaseCleaner::ActiveRecord
    when :data_mapper
      DatabaseCleaner::DataMapper
    when :mongo
      DatabaseCleaner::Mongo
    when :mongoid
      DatabaseCleaner::Mongoid
    when :mongo_mapper
      DatabaseCleaner::MongoMapper
    when :couch_potato
      DatabaseCleaner::CouchPotato
  end
end

.remove_duplicatesObject



67
68
69
70
71
72
73
# File 'lib/database_cleaner/configuration.rb', line 67

def remove_duplicates
  temp = []
  self.connections.each do |connect|
    temp.push connect unless temp.include? connect
  end
  @connections = temp
end

.startObject



51
52
53
# File 'lib/database_cleaner/configuration.rb', line 51

def start
  self.connections.each { |connection| connection.start }
end

.strategy=(stratagem) ⇒ Object



41
42
43
44
# File 'lib/database_cleaner/configuration.rb', line 41

def strategy=(stratagem)
  self.connections.each { |connect| connect.strategy = stratagem }
  remove_duplicates
end