Module: DatabaseCleaner

Defined in:
lib/database_cleaner.rb,
lib/database_cleaner/base.rb,
lib/database_cleaner/redis/base.rb,
lib/database_cleaner/moped/base.rb,
lib/database_cleaner/mongo/base.rb,
lib/database_cleaner/sequel/base.rb,
lib/database_cleaner/mongoid/base.rb,
lib/database_cleaner/generic/base.rb,
lib/database_cleaner/configuration.rb,
lib/database_cleaner/null_strategy.rb,
lib/database_cleaner/ohm/truncation.rb,
lib/database_cleaner/mongo/truncation.rb,
lib/database_cleaner/redis/truncation.rb,
lib/database_cleaner/moped/truncation.rb,
lib/database_cleaner/data_mapper/base.rb,
lib/database_cleaner/mongo_mapper/base.rb,
lib/database_cleaner/couch_potato/base.rb,
lib/database_cleaner/sequel/truncation.rb,
lib/database_cleaner/sequel/transaction.rb,
lib/database_cleaner/mongoid/truncation.rb,
lib/database_cleaner/generic/truncation.rb,
lib/database_cleaner/active_record/base.rb,
lib/database_cleaner/generic/transaction.rb,
lib/database_cleaner/moped/truncation_base.rb,
lib/database_cleaner/active_record/deletion.rb,
lib/database_cleaner/mongo/truncation_mixin.rb,
lib/database_cleaner/data_mapper/truncation.rb,
lib/database_cleaner/couch_potato/truncation.rb,
lib/database_cleaner/mongo_mapper/truncation.rb,
lib/database_cleaner/active_record/truncation.rb

Defined Under Namespace

Modules: ActiveRecord, ConnectionAdapters, CouchPotato, DataMapper, Generic, Mongo, MongoMapper, Mongoid, Moped, Ohm, Redis, Sequel Classes: Base, NoORMDetected, NullStrategy, UnknownStrategySpecified

Class Method Summary (collapse)

Class Method Details

+ (Object) [](orm, opts = {})

Raises:



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/database_cleaner/configuration.rb', line 15

def [](orm,opts = {})
  raise NoORMDetected unless orm
  init_cleaners
  # TODO: deprecate
  # this method conflates creation with lookup.  Both a command and a query. Yuck.
  if @cleaners.has_key? [orm, opts]
    @cleaners[[orm, opts]]
  else
    add_cleaner(orm, opts)
  end
end

+ (Object) add_cleaner(orm, opts = {})



27
28
29
30
31
32
33
# File 'lib/database_cleaner/configuration.rb', line 27

def add_cleaner(orm,opts = {})
  init_cleaners
  cleaner = DatabaseCleaner::Base.new(orm,opts)
  @cleaners[[orm, opts]] = cleaner
  @connections << cleaner
  cleaner
end

+ (Object) app_root



39
40
41
# File 'lib/database_cleaner/configuration.rb', line 39

def app_root
  @app_root ||= Dir.pwd
end

+ (Object) app_root=(desired_root)



35
36
37
# File 'lib/database_cleaner/configuration.rb', line 35

def app_root=(desired_root)
  @app_root = desired_root
end

+ (Boolean) can_detect_orm?



5
6
7
# File 'lib/database_cleaner.rb', line 5

def self.can_detect_orm?
  DatabaseCleaner::Base.autodetect_orm
end

+ (Object) clean Also known as: clean!



78
79
80
# File 'lib/database_cleaner/configuration.rb', line 78

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

+ (Object) clean_with(*args) Also known as: clean_with!



90
91
92
# File 'lib/database_cleaner/configuration.rb', line 90

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

+ (Object) cleaning(&inner_block)



84
85
86
87
88
# File 'lib/database_cleaner/configuration.rb', line 84

def cleaning(&inner_block)
  connections.inject(inner_block) do |curr_block, connection|
    proc { connection.cleaning(&curr_block) }
  end.call
end

+ (Object) connections



43
44
45
46
47
48
49
50
# File 'lib/database_cleaner/configuration.rb', line 43

def connections
  # double yuck.. can't wait to deprecate this whole class...
  unless @cleaners
    autodetected = ::DatabaseCleaner::Base.new
    add_cleaner(autodetected.orm)
  end
  @connections
end

+ (Object) init_cleaners



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

def init_cleaners
  @cleaners ||= {}
  # ghetto ordered hash.. maintains 1.8 compat and old API
  @connections ||= []
end

+ (Object) logger



56
57
58
59
60
61
62
# File 'lib/database_cleaner/configuration.rb', line 56

def logger
  return @logger if @logger

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

+ (Object) logger=(log_source)



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

def logger=(log_source)
  @logger = log_source
end

+ (Object) orm=(orm)



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

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

+ (Object) orm_module(symbol)



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/database_cleaner/configuration.rb', line 104

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 :moped
      DatabaseCleaner::Moped
    when :couch_potato
      DatabaseCleaner::CouchPotato
    when :sequel
      DatabaseCleaner::Sequel
    when :ohm
      DatabaseCleaner::Ohm
    when :redis
      DatabaseCleaner::Redis
  end
end

+ (Object) remove_duplicates



96
97
98
99
100
101
102
# File 'lib/database_cleaner/configuration.rb', line 96

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

+ (Object) start



74
75
76
# File 'lib/database_cleaner/configuration.rb', line 74

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

+ (Object) strategy=(stratagem)



64
65
66
67
# File 'lib/database_cleaner/configuration.rb', line 64

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