database_cleaner 1.7.0 → 1.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTE.markdown +1 -2
  3. data/Gemfile.lock +130 -91
  4. data/History.rdoc +45 -1
  5. data/README.markdown +74 -226
  6. data/Rakefile +12 -8
  7. data/adapters/database_cleaner-active_record/lib/database_cleaner-active_record.rb +1 -0
  8. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record.rb +6 -0
  9. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/base.rb +13 -4
  10. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/deletion.rb +19 -19
  11. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/transaction.rb +0 -0
  12. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/truncation.rb +25 -20
  13. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/version.rb +5 -0
  14. data/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb +1 -0
  15. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb +11 -0
  16. data/{lib → adapters/database_cleaner-couch_potato/lib}/database_cleaner/couch_potato/base.rb +0 -0
  17. data/{lib → adapters/database_cleaner-couch_potato/lib}/database_cleaner/couch_potato/truncation.rb +0 -0
  18. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb +5 -0
  19. data/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb +1 -0
  20. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb +4 -0
  21. data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/base.rb +4 -0
  22. data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/transaction.rb +0 -0
  23. data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/truncation.rb +4 -3
  24. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb +5 -0
  25. data/adapters/database_cleaner-mongo/lib/database_cleaner-mongo.rb +1 -0
  26. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb +10 -0
  27. data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/base.rb +0 -0
  28. data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/truncation.rb +2 -0
  29. data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/truncation_mixin.rb +0 -0
  30. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +5 -0
  31. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner-mongo_mapper.rb +1 -0
  32. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +4 -0
  33. data/{lib → adapters/database_cleaner-mongo_mapper/lib}/database_cleaner/mongo_mapper/base.rb +4 -0
  34. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb +35 -0
  35. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +5 -0
  36. data/adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb +1 -0
  37. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +10 -0
  38. data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongoid/base.rb +0 -0
  39. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb +26 -0
  40. data/{lib/database_cleaner/mongo2/truncation_mixin.rb → adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb} +3 -4
  41. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb +65 -0
  42. data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongoid/truncation.rb +6 -6
  43. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +5 -0
  44. data/adapters/database_cleaner-moped/lib/database_cleaner-moped.rb +1 -0
  45. data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +10 -0
  46. data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/base.rb +1 -1
  47. data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/truncation.rb +0 -0
  48. data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/truncation_base.rb +4 -0
  49. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +5 -0
  50. data/adapters/database_cleaner-neo4j/lib/database_cleaner-neo4j.rb +1 -0
  51. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +6 -0
  52. data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/base.rb +4 -0
  53. data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/deletion.rb +0 -0
  54. data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/transaction.rb +0 -0
  55. data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/truncation.rb +0 -0
  56. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +5 -0
  57. data/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb +1 -0
  58. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +12 -0
  59. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb +24 -0
  60. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +5 -0
  61. data/adapters/database_cleaner-redis/lib/database_cleaner-redis.rb +1 -0
  62. data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +4 -0
  63. data/{lib → adapters/database_cleaner-redis/lib}/database_cleaner/redis/base.rb +4 -0
  64. data/{lib → adapters/database_cleaner-redis/lib}/database_cleaner/redis/truncation.rb +0 -0
  65. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +5 -0
  66. data/adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb +1 -0
  67. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel.rb +6 -0
  68. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/base.rb +4 -0
  69. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/deletion.rb +0 -0
  70. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/transaction.rb +0 -0
  71. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/truncation.rb +16 -15
  72. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +5 -0
  73. data/lib/database_cleaner.rb +36 -1
  74. data/lib/database_cleaner/base.rb +92 -105
  75. data/lib/database_cleaner/configuration.rb +87 -83
  76. data/lib/database_cleaner/deprecation.rb +26 -0
  77. data/lib/database_cleaner/null_strategy.rb +6 -6
  78. data/lib/database_cleaner/orm_autodetector.rb +41 -0
  79. data/lib/database_cleaner/safeguard.rb +38 -3
  80. data/lib/database_cleaner/spec.rb +2 -0
  81. data/lib/database_cleaner/spec/database_helper.rb +82 -0
  82. data/lib/database_cleaner/spec/shared_examples.rb +15 -0
  83. data/lib/database_cleaner/version.rb +3 -0
  84. metadata +111 -44
  85. data/VERSION.yml +0 -4
  86. data/lib/database_cleaner/mongo2/base.rb +0 -16
  87. data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
  88. data/lib/database_cleaner/ohm/truncation.rb +0 -15
@@ -1,166 +1,153 @@
1
+ require 'database_cleaner/deprecation'
1
2
  require 'database_cleaner/null_strategy'
2
3
  require 'database_cleaner/safeguard'
4
+ require 'database_cleaner/orm_autodetector'
5
+ require 'forwardable'
6
+
3
7
  module DatabaseCleaner
4
8
  class Base
5
9
  include Comparable
6
10
 
7
11
  def <=>(other)
8
- (self.orm <=> other.orm) == 0 ? self.db <=> other.db : self.orm <=> other.orm
12
+ [orm, db] <=> [other.orm, other.db]
9
13
  end
10
14
 
11
- def initialize(desired_orm = nil,opts = {})
12
- if [:autodetect, nil, "autodetect"].include?(desired_orm)
13
- autodetect
14
- else
15
- self.orm = desired_orm
16
- end
15
+ def initialize(desired_orm = nil, opts = {})
16
+ @orm_autodetector = ORMAutodetector.new
17
+ self.orm = desired_orm
17
18
  self.db = opts[:connection] || opts[:model] if opts.has_key?(:connection) || opts.has_key?(:model)
18
- set_default_orm_strategy
19
+ self.strategy = orm_module && orm_module.default_strategy
19
20
  Safeguard.new.run
20
21
  end
21
22
 
22
23
  def db=(desired_db)
23
- self.strategy_db = desired_db
24
- @db = desired_db
25
- end
26
-
27
- def strategy_db=(desired_db)
28
- if strategy.respond_to? :db=
29
- strategy.db = desired_db
30
- elsif desired_db!= :default
31
- raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database"
32
- end
24
+ @db = self.strategy_db = desired_db
33
25
  end
34
26
 
35
27
  def db
36
28
  @db ||= :default
37
29
  end
38
30
 
39
- def create_strategy(*args)
31
+ def strategy=(args)
40
32
  strategy, *strategy_args = args
41
- orm_strategy(strategy).new(*strategy_args)
42
- end
33
+ @strategy = if strategy.is_a?(Symbol)
34
+ create_strategy(*args)
35
+ elsif strategy_args.empty?
36
+ strategy
37
+ else
38
+ raise ArgumentError, "You must provide a strategy object, or a symbol for a known strategy along with initialization params."
39
+ end
43
40
 
44
- def clean_with(*args)
45
- strategy = create_strategy(*args)
46
- set_strategy_db strategy, self.db
41
+ set_strategy_db @strategy, db
42
+ end
47
43
 
48
- strategy.clean
49
- strategy
44
+ def strategy
45
+ @strategy ||= NullStrategy.new
50
46
  end
51
47
 
52
- alias clean_with! clean_with
48
+ attr_reader :orm
53
49
 
54
- def set_strategy_db(strategy, desired_db)
55
- if strategy.respond_to? :db=
56
- strategy.db = desired_db
57
- elsif desired_db != :default
58
- raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database"
59
- end
50
+ def orm=(desired_orm)
51
+ @orm = (desired_orm || :autodetect).to_sym
52
+ @orm = @orm_autodetector.orm if @orm == :autodetect
60
53
  end
61
54
 
62
- def strategy=(args)
63
- strategy, *strategy_args = args
64
- if strategy.is_a?(Symbol)
65
- @strategy = create_strategy(*args)
66
- elsif strategy_args.empty?
67
- @strategy = strategy
68
- else
69
- raise ArgumentError, "You must provide a strategy object, or a symbol for a known strategy along with initialization params."
70
- end
55
+ extend Forwardable
56
+ delegate [:start, :clean, :cleaning] => :strategy
71
57
 
72
- set_strategy_db @strategy, self.db
73
-
74
- @strategy
58
+ def clean_with(*args)
59
+ strategy = create_strategy(*args)
60
+ set_strategy_db strategy, db
61
+ strategy.clean
62
+ strategy
75
63
  end
76
64
 
77
- def strategy
78
- @strategy ||= NullStrategy
79
- end
65
+ # TODO remove the following methods in 2.0
80
66
 
81
- def orm=(desired_orm)
82
- @orm = desired_orm.to_sym
67
+ def auto_detected?
68
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].auto_detected?` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
69
+ @orm_autodetector.autodetected?
83
70
  end
84
71
 
85
- def orm
86
- @orm || autodetect
72
+ def autodetect_orm
73
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].autodetect_orm` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
74
+ @orm_autodetector.orm
87
75
  end
88
76
 
89
- def start
90
- strategy.start
77
+ def clean!
78
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].clean!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].clean instead."
79
+ clean
91
80
  end
92
81
 
93
- def clean
94
- strategy.clean
82
+ def clean_with!
83
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].clean_with!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].clean_with instead."
84
+ clean_with
95
85
  end
96
86
 
97
- alias clean! clean
87
+ # TODO privatize the following methods in 2.0
98
88
 
99
- def cleaning(&block)
100
- strategy.cleaning(&block)
89
+ def strategy_db=(desired_db)
90
+ if DatabaseCleaner.called_externally?(__FILE__, caller)
91
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].strategy_db=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].db=` instead."
92
+ end
93
+ set_strategy_db(strategy, desired_db)
101
94
  end
102
95
 
103
- def auto_detected?
104
- !!@autodetected
96
+ def set_strategy_db(strategy, desired_db)
97
+ if DatabaseCleaner.called_externally?(__FILE__, caller)
98
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].set_strategy_db=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].db=` instead."
99
+ end
100
+ if strategy.respond_to? :db=
101
+ strategy.db = desired_db
102
+ elsif desired_db != :default
103
+ raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database"
104
+ end
105
105
  end
106
106
 
107
- def autodetect_orm
108
- if defined? ::ActiveRecord
109
- :active_record
110
- elsif defined? ::DataMapper
111
- :data_mapper
112
- elsif defined? ::MongoMapper
113
- :mongo_mapper
114
- elsif defined? ::Mongoid
115
- :mongoid
116
- elsif defined? ::CouchPotato
117
- :couch_potato
118
- elsif defined? ::Sequel
119
- :sequel
120
- elsif defined? ::Moped
121
- :moped
122
- elsif defined? ::Ohm
123
- :ohm
124
- elsif defined? ::Redis
125
- :redis
126
- elsif defined? ::Neo4j
127
- :neo4j
107
+ def create_strategy(*args)
108
+ if DatabaseCleaner.called_externally?(__FILE__, caller)
109
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].create_strategy` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].strategy=` instead."
128
110
  end
111
+ strategy, *strategy_args = args
112
+ orm_strategy(strategy).new(*strategy_args)
129
113
  end
130
114
 
131
115
  private
132
116
 
133
117
  def orm_module
134
- ::DatabaseCleaner.orm_module(orm)
118
+ return unless [:active_record, :data_mapper, :mongo, :mongoid, :mongo_mapper, :moped, :couch_potato, :sequel, :ohm, :redis, :neo4j].include?(orm)
119
+ load_adapter(orm) if !adapter_loaded?(orm)
120
+ orm_module_name = ORMAutodetector::ORMS[orm]
121
+ DatabaseCleaner.const_get(orm_module_name, false)
135
122
  end
136
123
 
137
- def orm_strategy(strategy)
138
- require "database_cleaner/#{orm.to_s}/#{strategy.to_s}"
139
- orm_module.const_get(strategy.to_s.capitalize)
140
- rescue LoadError
141
- if orm_module.respond_to? :available_strategies
142
- raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}"
143
- else
144
- raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM!"
145
- end
124
+ def adapter_loaded? orm
125
+ $LOADED_FEATURES.grep(%r{/lib/database_cleaner/#{orm}\.rb$}).any?
146
126
  end
147
127
 
148
- def autodetect
149
- @autodetected = true
150
-
151
- @orm ||= autodetect_orm ||
152
- raise(NoORMDetected, "No known ORM was detected! Is ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, Moped, or CouchPotato, Redis or Ohm loaded?")
128
+ def load_adapter orm
129
+ $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../adapters/database_cleaner-#{orm}/lib")
130
+ require "database_cleaner/#{orm}"
153
131
  end
154
132
 
155
- def set_default_orm_strategy
156
- case orm
157
- when :active_record, :data_mapper, :sequel
158
- self.strategy = :transaction
159
- when :mongo_mapper, :mongoid, :couch_potato, :moped, :ohm, :redis
160
- self.strategy = :truncation
161
- when :neo4j
162
- self.strategy = :transaction
133
+ def orm_strategy(strategy)
134
+ strategy_module_name = strategy.to_s.capitalize
135
+ orm_module.const_get(strategy_module_name, false)
136
+ rescue NameError
137
+ if orm != :active_record
138
+ DatabaseCleaner.deprecate <<-TEXT
139
+ 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.
140
+ TEXT
163
141
  end
142
+ require_orm_strategy(orm, strategy)
143
+ retry
144
+ end
145
+
146
+ def require_orm_strategy(orm, strategy)
147
+ $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../adapters/database_cleaner-#{orm}/lib")
148
+ require "database_cleaner/#{orm}/#{strategy}"
149
+ rescue LoadError
150
+ raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}"
164
151
  end
165
152
  end
166
153
  end
@@ -1,74 +1,77 @@
1
1
  require 'database_cleaner/base'
2
+ require 'database_cleaner/deprecation'
3
+ require 'forwardable'
2
4
 
3
5
  module DatabaseCleaner
4
6
 
5
- class NoORMDetected < StandardError; end
6
- class UnknownStrategySpecified < ArgumentError; end
7
+ class NoORMDetected < StandardError; end
8
+ class UnknownStrategySpecified < ArgumentError; end
7
9
 
8
- class << self
9
- def init_cleaners
10
- @cleaners ||= {}
11
- # ghetto ordered hash.. maintains 1.8 compat and old API
12
- @connections ||= []
13
- end
14
-
15
- def [](orm,opts = {})
10
+ class Cleaners < Hash
11
+ # FIXME this method conflates creation with lookup... both a command and a query. yuck.
12
+ def [](orm, opts = {})
16
13
  raise NoORMDetected unless orm
17
- init_cleaners
18
- # TODO: deprecate
19
- # this method conflates creation with lookup. Both a command and a query. Yuck.
20
- if @cleaners.has_key? [orm, opts]
21
- @cleaners[[orm, opts]]
22
- else
23
- add_cleaner(orm, opts)
24
- end
25
- end
14
+ fetch([orm, opts]) { add_cleaner(orm, opts) }
15
+ end
26
16
 
27
- def add_cleaner(orm,opts = {})
28
- init_cleaners
29
- cleaner = DatabaseCleaner::Base.new(orm,opts)
30
- @cleaners[[orm, opts]] = cleaner
31
- @connections << cleaner
32
- cleaner
17
+ def strategy=(strategy)
18
+ add_cleaner(:autodetect) if none?
19
+ values.each { |cleaner| cleaner.strategy = strategy }
20
+ remove_duplicates
33
21
  end
34
22
 
35
- def app_root=(desired_root)
36
- @app_root = desired_root
23
+ def orm=(orm)
24
+ add_cleaner(:autodetect) if none?
25
+ values.each { |cleaner| cleaner.orm = orm }
26
+ remove_duplicates
37
27
  end
38
28
 
39
- def app_root
40
- @app_root ||= Dir.pwd
29
+ # TODO privatize the following methods in 2.0
30
+
31
+ def add_cleaner(orm, opts = {})
32
+ self[[orm, opts]] = ::DatabaseCleaner::Base.new(orm, opts)
41
33
  end
42
34
 
43
- def connections
44
- # double yuck.. can't wait to deprecate this whole class...
45
- unless defined?(@cleaners) && @cleaners
46
- autodetected = ::DatabaseCleaner::Base.new
47
- add_cleaner(autodetected.orm)
48
- end
49
- @connections
35
+ def remove_duplicates
36
+ replace(reduce(Cleaners.new) do |cleaners, (key, value)|
37
+ cleaners[key] = value unless cleaners.values.include?(value)
38
+ cleaners
39
+ end)
50
40
  end
41
+ end
51
42
 
52
- def logger=(log_source)
53
- @logger = log_source
43
+ class Configuration
44
+ def initialize
45
+ @cleaners ||= Cleaners.new
54
46
  end
55
47
 
56
- def logger
57
- return @logger if @logger
48
+ extend Forwardable
49
+ delegate [
50
+ :[],
51
+ :strategy=,
52
+ :orm=,
53
+ ] => :cleaners
58
54
 
59
- @logger = Logger.new(STDOUT)
60
- @logger.level = Logger::ERROR
61
- @logger
55
+ attr_accessor :cleaners
56
+
57
+ def app_root
58
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner.app_root` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner::ActiveRecord.config_file_location`, instead."
59
+ @app_root ||= Dir.pwd
62
60
  end
63
61
 
64
- def strategy=(stratagem)
65
- connections.each { |connect| connect.strategy = stratagem }
66
- remove_duplicates
62
+ def app_root= value
63
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner.app_root=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner::ActiveRecord.config_file_location=`, instead."
64
+ @app_root = value
67
65
  end
68
66
 
69
- def orm=(orm)
70
- connections.each { |connect| connect.orm = orm }
71
- remove_duplicates
67
+ def logger
68
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner.logger` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
69
+ @logger ||= Logger.new(STDOUT).tap { |l| l.level = Logger::ERROR }
70
+ end
71
+
72
+ def logger= value
73
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner.logger=` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
74
+ @logger = value
72
75
  end
73
76
 
74
77
  def start
@@ -79,8 +82,6 @@ module DatabaseCleaner
79
82
  connections.each { |connection| connection.clean }
80
83
  end
81
84
 
82
- alias clean! clean
83
-
84
85
  def cleaning(&inner_block)
85
86
  connections.inject(inner_block) do |curr_block, connection|
86
87
  proc { connection.cleaning(&curr_block) }
@@ -91,41 +92,44 @@ module DatabaseCleaner
91
92
  connections.each { |connection| connection.clean_with(*args) }
92
93
  end
93
94
 
94
- alias clean_with! clean_with
95
+ # TODO remove the following methods in 2.0
95
96
 
96
- def remove_duplicates
97
- temp = []
98
- connections.each do |connect|
99
- temp.push connect unless temp.include? connect
97
+ def clean!
98
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner.clean!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.clean`, instead."
99
+ clean
100
+ end
101
+
102
+ def clean_with!(*args)
103
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner.clean_with!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.clean_with`, instead."
104
+ clean_with(*args)
105
+ end
106
+
107
+ def init_cleaners
108
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner.init_cleaners` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
109
+ end
110
+
111
+ def connections
112
+ if DatabaseCleaner.called_externally?(__FILE__, caller)
113
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner.connections` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.cleaners`, instead."
114
+ end
115
+ add_cleaner(:autodetect) if @cleaners.none?
116
+ @cleaners.values
117
+ end
118
+
119
+ # TODO privatize the following methods in 2.0
120
+
121
+ def add_cleaner(orm, opts = {})
122
+ if DatabaseCleaner.called_externally?(__FILE__, caller)
123
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner.add_cleaner` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.[]`, instead."
100
124
  end
101
- @connections = temp
102
- end
103
-
104
- def orm_module(symbol)
105
- case symbol
106
- when :active_record
107
- DatabaseCleaner::ActiveRecord
108
- when :data_mapper
109
- DatabaseCleaner::DataMapper
110
- when :mongo
111
- DatabaseCleaner::Mongo
112
- when :mongoid
113
- DatabaseCleaner::Mongoid
114
- when :mongo_mapper
115
- DatabaseCleaner::MongoMapper
116
- when :moped
117
- DatabaseCleaner::Moped
118
- when :couch_potato
119
- DatabaseCleaner::CouchPotato
120
- when :sequel
121
- DatabaseCleaner::Sequel
122
- when :ohm
123
- DatabaseCleaner::Ohm
124
- when :redis
125
- DatabaseCleaner::Redis
126
- when :neo4j
127
- DatabaseCleaner::Neo4j
125
+ @cleaners.add_cleaner(orm, opts = {})
126
+ end
127
+
128
+ def remove_duplicates
129
+ if DatabaseCleaner.called_externally?(__FILE__, caller)
130
+ DatabaseCleaner.deprecate "Calling `DatabaseCleaner.remove_duplicates` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
128
131
  end
132
+ @cleaners.remove_duplicates
129
133
  end
130
134
  end
131
135
  end