database_cleaner 1.99.0 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/database_cleaner.rb +1 -47
- metadata +14 -484
- data/CONTRIBUTE.markdown +0 -27
- data/Gemfile.lock +0 -324
- data/History.rdoc +0 -514
- data/LICENSE +0 -20
- data/README.markdown +0 -389
- data/Rakefile +0 -44
- data/TODO +0 -3
- data/adapters/database_cleaner-active_record/lib/database_cleaner-active_record.rb +0 -1
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record.rb +0 -6
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/base.rb +0 -101
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/deletion.rb +0 -108
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/transaction.rb +0 -59
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/truncation.rb +0 -288
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/version.rb +0 -5
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb +0 -1
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb +0 -13
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/base.rb +0 -7
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/truncation.rb +0 -28
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb +0 -5
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb +0 -1
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb +0 -6
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/base.rb +0 -25
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/transaction.rb +0 -28
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/truncation.rb +0 -173
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb +0 -5
- data/adapters/database_cleaner-mongo/lib/database_cleaner-mongo.rb +0 -1
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb +0 -11
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/base.rb +0 -16
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/deletion.rb +0 -8
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation.rb +0 -74
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +0 -5
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner-mongo_mapper.rb +0 -1
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +0 -5
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/base.rb +0 -24
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb +0 -35
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +0 -5
- data/adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb +0 -1
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +0 -11
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/base.rb +0 -20
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/deletion.rb +0 -10
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb +0 -26
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb +0 -38
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb +0 -65
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/truncation.rb +0 -49
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +0 -5
- data/adapters/database_cleaner-moped/lib/database_cleaner-moped.rb +0 -1
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +0 -12
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/base.rb +0 -39
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/truncation.rb +0 -9
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/truncation_base.rb +0 -44
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +0 -5
- data/adapters/database_cleaner-neo4j/lib/database_cleaner-neo4j.rb +0 -1
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +0 -7
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/base.rb +0 -66
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/deletion.rb +0 -16
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/transaction.rb +0 -35
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/truncation.rb +0 -9
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +0 -5
- data/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb +0 -1
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +0 -12
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb +0 -24
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +0 -5
- data/adapters/database_cleaner-redis/lib/database_cleaner-redis.rb +0 -1
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +0 -5
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/base.rb +0 -45
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/deletion.rb +0 -9
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/truncation.rb +0 -26
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +0 -5
- data/adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb +0 -1
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel.rb +0 -6
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/base.rb +0 -26
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/deletion.rb +0 -47
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb +0 -40
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/truncation.rb +0 -79
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +0 -5
- data/cucumber.yml +0 -1
- data/lib/database_cleaner/base.rb +0 -169
- data/lib/database_cleaner/configuration.rb +0 -136
- data/lib/database_cleaner/cucumber.rb +0 -3
- data/lib/database_cleaner/deprecation.rb +0 -26
- data/lib/database_cleaner/generic/base.rb +0 -29
- data/lib/database_cleaner/generic/transaction.rb +0 -11
- data/lib/database_cleaner/generic/truncation.rb +0 -40
- data/lib/database_cleaner/null_strategy.rb +0 -20
- data/lib/database_cleaner/orm_autodetector.rb +0 -41
- data/lib/database_cleaner/safeguard.rb +0 -107
- data/lib/database_cleaner/spec.rb +0 -2
- data/lib/database_cleaner/spec/database_helper.rb +0 -82
- data/lib/database_cleaner/spec/shared_examples.rb +0 -15
- data/lib/database_cleaner/version.rb +0 -3
data/cucumber.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
default: features
|
@@ -1,169 +0,0 @@
|
|
1
|
-
require 'database_cleaner/deprecation'
|
2
|
-
require 'database_cleaner/null_strategy'
|
3
|
-
require 'database_cleaner/safeguard'
|
4
|
-
require 'database_cleaner/orm_autodetector'
|
5
|
-
require 'forwardable'
|
6
|
-
|
7
|
-
module DatabaseCleaner
|
8
|
-
class Base
|
9
|
-
include Comparable
|
10
|
-
|
11
|
-
def <=>(other)
|
12
|
-
[orm, db] <=> [other.orm, other.db]
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(desired_orm = nil, opts = {})
|
16
|
-
@orm_autodetector = ORMAutodetector.new
|
17
|
-
self.orm = desired_orm
|
18
|
-
if opts.has_key?(:model)
|
19
|
-
DatabaseCleaner.deprecate "Using the `:model` key in `DatabaseCleaner[:orm, model: ...]` is deprecated, and will be removed in database_cleaner 2.0. Please use the new `:db` key, instead, which has identical behavior: `DatabaseCleaner[:orm, db: ...]`."
|
20
|
-
end
|
21
|
-
if opts.has_key?(:connection)
|
22
|
-
DatabaseCleaner.deprecate "Using the `:connection` key in `DatabaseCleaner[:orm, connection: ...]` is deprecated, and will be removed in database_cleaner 2.0. Please use the new `:db` key, instead, which has identical behavior: `DatabaseCleaner[:orm, db: ...]`."
|
23
|
-
end
|
24
|
-
self.db = opts[:db] || opts[:connection] || opts[:model] if opts.has_key?(:db) || opts.has_key?(:connection) || opts.has_key?(:model)
|
25
|
-
self.strategy = orm_module && orm_module.default_strategy
|
26
|
-
Safeguard.new.run
|
27
|
-
end
|
28
|
-
|
29
|
-
def db=(desired_db)
|
30
|
-
@db = self.strategy_db = desired_db
|
31
|
-
end
|
32
|
-
|
33
|
-
def db
|
34
|
-
@db ||= :default
|
35
|
-
end
|
36
|
-
|
37
|
-
def strategy=(args)
|
38
|
-
strategy, *strategy_args = args
|
39
|
-
|
40
|
-
if DatabaseCleaner.called_externally?(__FILE__, caller) \
|
41
|
-
&& [:redis, :mongo, :mongoid].include?(orm) \
|
42
|
-
&& strategy == :truncation
|
43
|
-
DatabaseCleaner.deprecate "The #{orm} adapter's :truncation strategy will be renamed to :deletion in database_cleaner-#{orm} 2.0. Please specify the :deletion adapter to resolve this deprecation notice."
|
44
|
-
end
|
45
|
-
|
46
|
-
@strategy = if strategy.is_a?(Symbol)
|
47
|
-
create_strategy(*args)
|
48
|
-
elsif strategy_args.empty?
|
49
|
-
strategy
|
50
|
-
else
|
51
|
-
raise ArgumentError, "You must provide a strategy object, or a symbol for a known strategy along with initialization params."
|
52
|
-
end
|
53
|
-
|
54
|
-
set_strategy_db @strategy, db
|
55
|
-
end
|
56
|
-
|
57
|
-
def strategy
|
58
|
-
@strategy ||= NullStrategy.new
|
59
|
-
end
|
60
|
-
|
61
|
-
attr_reader :orm
|
62
|
-
|
63
|
-
def orm=(desired_orm)
|
64
|
-
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
65
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[:orm].orm=` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
66
|
-
end
|
67
|
-
@orm = (desired_orm || :autodetect).to_sym
|
68
|
-
@orm = @orm_autodetector.orm if @orm == :autodetect
|
69
|
-
end
|
70
|
-
|
71
|
-
extend Forwardable
|
72
|
-
delegate [:start, :clean, :cleaning] => :strategy
|
73
|
-
|
74
|
-
def clean_with(*args)
|
75
|
-
strategy = create_strategy(*args)
|
76
|
-
set_strategy_db strategy, db
|
77
|
-
strategy.clean
|
78
|
-
strategy
|
79
|
-
end
|
80
|
-
|
81
|
-
# TODO remove the following methods in 2.0
|
82
|
-
|
83
|
-
def auto_detected?
|
84
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].auto_detected?` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
85
|
-
@orm_autodetector.autodetected?
|
86
|
-
end
|
87
|
-
|
88
|
-
def autodetect_orm
|
89
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].autodetect_orm` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
90
|
-
@orm_autodetector.orm
|
91
|
-
end
|
92
|
-
|
93
|
-
def clean!
|
94
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].clean!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].clean instead."
|
95
|
-
clean
|
96
|
-
end
|
97
|
-
|
98
|
-
def clean_with!
|
99
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].clean_with!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].clean_with instead."
|
100
|
-
clean_with
|
101
|
-
end
|
102
|
-
|
103
|
-
# TODO privatize the following methods in 2.0
|
104
|
-
|
105
|
-
def strategy_db=(desired_db)
|
106
|
-
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
107
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].strategy_db=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].db=` instead."
|
108
|
-
end
|
109
|
-
set_strategy_db(strategy, desired_db)
|
110
|
-
end
|
111
|
-
|
112
|
-
def set_strategy_db(strategy, desired_db)
|
113
|
-
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
114
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].set_strategy_db=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].db=` instead."
|
115
|
-
end
|
116
|
-
if strategy.respond_to? :db=
|
117
|
-
strategy.db = desired_db
|
118
|
-
elsif desired_db != :default
|
119
|
-
raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def create_strategy(*args)
|
124
|
-
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
125
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].create_strategy` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].strategy=` instead."
|
126
|
-
end
|
127
|
-
strategy, *strategy_args = args
|
128
|
-
orm_strategy(strategy).new(*strategy_args)
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
|
133
|
-
def orm_module
|
134
|
-
return unless [:active_record, :data_mapper, :mongo, :mongoid, :mongo_mapper, :moped, :couch_potato, :sequel, :ohm, :redis, :neo4j].include?(orm)
|
135
|
-
load_adapter(orm) if !adapter_loaded?(orm)
|
136
|
-
orm_module_name = ORMAutodetector::ORMS[orm]
|
137
|
-
DatabaseCleaner.const_get(orm_module_name, false)
|
138
|
-
end
|
139
|
-
|
140
|
-
def adapter_loaded? orm
|
141
|
-
$LOADED_FEATURES.grep(%r{/lib/database_cleaner/#{orm}\.rb$}).any?
|
142
|
-
end
|
143
|
-
|
144
|
-
def load_adapter orm
|
145
|
-
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../adapters/database_cleaner-#{orm}/lib")
|
146
|
-
require "database_cleaner/#{orm}"
|
147
|
-
end
|
148
|
-
|
149
|
-
def orm_strategy(strategy)
|
150
|
-
strategy_module_name = strategy.to_s.capitalize
|
151
|
-
orm_module.const_get(strategy_module_name, false)
|
152
|
-
rescue NameError
|
153
|
-
if orm != :active_record
|
154
|
-
DatabaseCleaner.deprecate <<-TEXT
|
155
|
-
The #{orm_module} adapter has been extracted to its own gem: database_cleaner-#{orm}, and will be removed from database_cleaner in 2.0. To silence this message, please replace `gem "database_cleaner"` with `gem "database_cleaner-#{orm}"` in your Gemfile.
|
156
|
-
TEXT
|
157
|
-
end
|
158
|
-
require_orm_strategy(orm, strategy)
|
159
|
-
retry
|
160
|
-
end
|
161
|
-
|
162
|
-
def require_orm_strategy(orm, strategy)
|
163
|
-
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../adapters/database_cleaner-#{orm}/lib")
|
164
|
-
require "database_cleaner/#{orm}/#{strategy}"
|
165
|
-
rescue LoadError
|
166
|
-
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}"
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
require 'database_cleaner/base'
|
2
|
-
require 'database_cleaner/deprecation'
|
3
|
-
require 'forwardable'
|
4
|
-
|
5
|
-
module DatabaseCleaner
|
6
|
-
|
7
|
-
class NoORMDetected < StandardError; end
|
8
|
-
class UnknownStrategySpecified < ArgumentError; end
|
9
|
-
|
10
|
-
class Cleaners < Hash
|
11
|
-
# FIXME this method conflates creation with lookup... both a command and a query. yuck.
|
12
|
-
def [](orm, opts = {})
|
13
|
-
raise NoORMDetected unless orm
|
14
|
-
fetch([orm, opts]) { add_cleaner(orm, opts) }
|
15
|
-
end
|
16
|
-
|
17
|
-
def strategy=(strategy)
|
18
|
-
add_cleaner(:autodetect) if none?
|
19
|
-
values.each { |cleaner| cleaner.strategy = strategy }
|
20
|
-
remove_duplicates
|
21
|
-
end
|
22
|
-
|
23
|
-
def orm=(orm)
|
24
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.orm=` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
25
|
-
add_cleaner(:autodetect) if none?
|
26
|
-
values.each { |cleaner| cleaner.orm = orm }
|
27
|
-
remove_duplicates
|
28
|
-
end
|
29
|
-
|
30
|
-
# TODO privatize the following methods in 2.0
|
31
|
-
|
32
|
-
def add_cleaner(orm, opts = {})
|
33
|
-
self[[orm, opts]] = ::DatabaseCleaner::Base.new(orm, opts)
|
34
|
-
end
|
35
|
-
|
36
|
-
def remove_duplicates
|
37
|
-
replace(reduce(Cleaners.new) do |cleaners, (key, value)|
|
38
|
-
cleaners[key] = value unless cleaners.values.include?(value)
|
39
|
-
cleaners
|
40
|
-
end)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class Configuration
|
45
|
-
def initialize
|
46
|
-
@cleaners ||= Cleaners.new
|
47
|
-
end
|
48
|
-
|
49
|
-
extend Forwardable
|
50
|
-
delegate [
|
51
|
-
:[],
|
52
|
-
:strategy=,
|
53
|
-
:orm=,
|
54
|
-
] => :cleaners
|
55
|
-
|
56
|
-
attr_accessor :cleaners
|
57
|
-
|
58
|
-
def app_root
|
59
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.app_root` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner::ActiveRecord.config_file_location`, instead."
|
60
|
-
@app_root ||= Dir.pwd
|
61
|
-
end
|
62
|
-
|
63
|
-
def app_root= value
|
64
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.app_root=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner::ActiveRecord.config_file_location=`, instead."
|
65
|
-
@app_root = value
|
66
|
-
end
|
67
|
-
|
68
|
-
def logger
|
69
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.logger` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
70
|
-
@logger ||= Logger.new(STDOUT).tap { |l| l.level = Logger::ERROR }
|
71
|
-
end
|
72
|
-
|
73
|
-
def logger= value
|
74
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.logger=` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
75
|
-
@logger = value
|
76
|
-
end
|
77
|
-
|
78
|
-
def start
|
79
|
-
connections.each { |connection| connection.start }
|
80
|
-
end
|
81
|
-
|
82
|
-
def clean
|
83
|
-
connections.each { |connection| connection.clean }
|
84
|
-
end
|
85
|
-
|
86
|
-
def cleaning(&inner_block)
|
87
|
-
connections.inject(inner_block) do |curr_block, connection|
|
88
|
-
proc { connection.cleaning(&curr_block) }
|
89
|
-
end.call
|
90
|
-
end
|
91
|
-
|
92
|
-
def clean_with(*args)
|
93
|
-
connections.each { |connection| connection.clean_with(*args) }
|
94
|
-
end
|
95
|
-
|
96
|
-
# TODO remove the following methods in 2.0
|
97
|
-
|
98
|
-
def clean!
|
99
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.clean!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.clean`, instead."
|
100
|
-
clean
|
101
|
-
end
|
102
|
-
|
103
|
-
def clean_with!(*args)
|
104
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.clean_with!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.clean_with`, instead."
|
105
|
-
clean_with(*args)
|
106
|
-
end
|
107
|
-
|
108
|
-
def init_cleaners
|
109
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.init_cleaners` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
110
|
-
end
|
111
|
-
|
112
|
-
def connections
|
113
|
-
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
114
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.connections` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.cleaners.values`, instead."
|
115
|
-
end
|
116
|
-
add_cleaner(:autodetect) if @cleaners.none?
|
117
|
-
@cleaners.values
|
118
|
-
end
|
119
|
-
|
120
|
-
# TODO privatize the following methods in 2.0
|
121
|
-
|
122
|
-
def add_cleaner(orm, opts = {})
|
123
|
-
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
124
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.add_cleaner` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.[]`, instead."
|
125
|
-
end
|
126
|
-
@cleaners.add_cleaner(orm, opts = {})
|
127
|
-
end
|
128
|
-
|
129
|
-
def remove_duplicates
|
130
|
-
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
131
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.remove_duplicates` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
132
|
-
end
|
133
|
-
@cleaners.remove_duplicates
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module DatabaseCleaner
|
2
|
-
def deprecate message
|
3
|
-
method = caller.first[/\d+:in `(.*)'$/, 1].to_sym
|
4
|
-
@@deprecator ||= Deprecator.new
|
5
|
-
@@deprecator.deprecate method, message
|
6
|
-
end
|
7
|
-
module_function :deprecate
|
8
|
-
|
9
|
-
def called_externally?(file, caller)
|
10
|
-
file != caller.first[/^(.+\.rb):\d+/, 1]
|
11
|
-
end
|
12
|
-
module_function :called_externally?
|
13
|
-
|
14
|
-
class Deprecator
|
15
|
-
def initialize
|
16
|
-
@methods_already_warned = {}
|
17
|
-
end
|
18
|
-
|
19
|
-
def deprecate method, message
|
20
|
-
return if @methods_already_warned.key?(method)
|
21
|
-
$stderr.puts message
|
22
|
-
@methods_already_warned[method] = true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module ::DatabaseCleaner
|
2
|
-
module Generic
|
3
|
-
module Base
|
4
|
-
|
5
|
-
def self.included(base)
|
6
|
-
base.extend(ClassMethods)
|
7
|
-
end
|
8
|
-
|
9
|
-
def db
|
10
|
-
:default
|
11
|
-
end
|
12
|
-
|
13
|
-
def cleaning(&block)
|
14
|
-
begin
|
15
|
-
start
|
16
|
-
yield
|
17
|
-
ensure
|
18
|
-
clean
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module ClassMethods
|
23
|
-
def available_strategies
|
24
|
-
%W[]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module DatabaseCleaner
|
2
|
-
module Generic
|
3
|
-
module Truncation
|
4
|
-
def initialize(opts={})
|
5
|
-
if !opts.empty? && !(opts.keys - [:only, :except, :pre_count, :reset_ids, :cache_tables]).empty?
|
6
|
-
raise ArgumentError, "The only valid options are :only, :except, :pre_count, :reset_ids or :cache_tables. You specified #{opts.keys.join(',')}."
|
7
|
-
end
|
8
|
-
if opts.has_key?(:only) && opts.has_key?(:except)
|
9
|
-
raise ArgumentError, "You may only specify either :only or :except. Doing both doesn't really make sense does it?"
|
10
|
-
end
|
11
|
-
|
12
|
-
@only = opts[:only]
|
13
|
-
@tables_to_exclude = Array( (opts[:except] || []).dup ).flatten
|
14
|
-
@tables_to_exclude += migration_storage_names
|
15
|
-
@pre_count = opts[:pre_count]
|
16
|
-
@reset_ids = opts[:reset_ids]
|
17
|
-
@cache_tables = opts.has_key?(:cache_tables) ? !!opts[:cache_tables] : true
|
18
|
-
end
|
19
|
-
|
20
|
-
def start
|
21
|
-
#included for compatability reasons, do nothing if you don't need to
|
22
|
-
end
|
23
|
-
|
24
|
-
def clean
|
25
|
-
raise NotImplementedError
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
def tables_to_truncate
|
30
|
-
raise NotImplementedError
|
31
|
-
end
|
32
|
-
|
33
|
-
# overwrite in subclasses
|
34
|
-
# default implementation given because migration storage need not be present
|
35
|
-
def migration_storage_names
|
36
|
-
%w[]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|