Module: DatabaseCleaner
- Defined in:
- lib/database_cleaner.rb,
lib/database_cleaner/base.rb,
lib/database_cleaner/mongo/base.rb,
lib/database_cleaner/moped/base.rb,
lib/database_cleaner/redis/base.rb,
lib/database_cleaner/sequel/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/ohm/truncation.rb,
lib/database_cleaner/data_mapper/base.rb,
lib/database_cleaner/mongo/truncation.rb,
lib/database_cleaner/moped/truncation.rb,
lib/database_cleaner/redis/truncation.rb,
lib/database_cleaner/couch_potato/base.rb,
lib/database_cleaner/mongo_mapper/base.rb,
lib/database_cleaner/sequel/truncation.rb,
lib/database_cleaner/active_record/base.rb,
lib/database_cleaner/generic/truncation.rb,
lib/database_cleaner/mongoid/truncation.rb,
lib/database_cleaner/sequel/transaction.rb,
lib/database_cleaner/generic/transaction.rb,
lib/database_cleaner/moped/truncation_base.rb,
lib/database_cleaner/active_record/deletion.rb,
lib/database_cleaner/data_mapper/truncation.rb,
lib/database_cleaner/mongo/truncation_mixin.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
.[](orm, opts = {}) ⇒ Object
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
if @cleaners.has_key? [orm, opts]
@cleaners[[orm, opts]]
else
add_cleaner(orm, opts)
end
end
|
.add_cleaner(orm, opts = {}) ⇒ Object
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
|
.app_root ⇒ Object
39
40
41
|
# File 'lib/database_cleaner/configuration.rb', line 39
def app_root
@app_root ||= Dir.pwd
end
|
.app_root=(desired_root) ⇒ Object
35
36
37
|
# File 'lib/database_cleaner/configuration.rb', line 35
def app_root=(desired_root)
@app_root = desired_root
end
|
.can_detect_orm? ⇒ Boolean
.clean ⇒ Object
Also known as:
clean!
78
79
80
|
# File 'lib/database_cleaner/configuration.rb', line 78
def clean
connections.each { |connection| connection.clean }
end
|
.clean_with(*args) ⇒ Object
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
|
.cleaning(&inner_block) ⇒ Object
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
|
.connections ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/database_cleaner/configuration.rb', line 43
def connections
unless @cleaners
autodetected = ::DatabaseCleaner::Base.new
add_cleaner(autodetected.orm)
end
@connections
end
|
.init_cleaners ⇒ Object
9
10
11
12
13
|
# File 'lib/database_cleaner/configuration.rb', line 9
def init_cleaners
@cleaners ||= {}
@connections ||= []
end
|
.logger ⇒ Object
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
|
.logger=(log_source) ⇒ Object
52
53
54
|
# File 'lib/database_cleaner/configuration.rb', line 52
def logger=(log_source)
@logger = log_source
end
|
.orm=(orm) ⇒ Object
69
70
71
72
|
# File 'lib/database_cleaner/configuration.rb', line 69
def orm=(orm)
connections.each { |connect| connect.orm = orm }
remove_duplicates
end
|
.orm_module(symbol) ⇒ Object
.remove_duplicates ⇒ Object
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
|
.start ⇒ Object
74
75
76
|
# File 'lib/database_cleaner/configuration.rb', line 74
def start
connections.each { |connection| connection.start }
end
|
.strategy=(stratagem) ⇒ Object
64
65
66
67
|
# File 'lib/database_cleaner/configuration.rb', line 64
def strategy=(stratagem)
connections.each { |connect| connect.strategy = stratagem }
remove_duplicates
end
|