database_cleaner 1.6.2 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +5 -5
  2. data/lib/database_cleaner.rb +1 -8
  3. metadata +25 -499
  4. data/CONTRIBUTE.markdown +0 -28
  5. data/Gemfile.lock +0 -286
  6. data/History.rdoc +0 -430
  7. data/LICENSE +0 -20
  8. data/README.markdown +0 -518
  9. data/Rakefile +0 -40
  10. data/TODO +0 -3
  11. data/VERSION.yml +0 -4
  12. data/cucumber.yml +0 -1
  13. data/examples/Gemfile +0 -1
  14. data/examples/Gemfile.lock +0 -1
  15. data/examples/config/database.yml.example +0 -8
  16. data/examples/config/redis.yml +0 -8
  17. data/examples/db/sqlite_databases_go_here +0 -0
  18. data/examples/features/example.feature +0 -11
  19. data/examples/features/example_multiple_db.feature +0 -23
  20. data/examples/features/example_multiple_orm.feature +0 -22
  21. data/examples/features/step_definitions/activerecord_steps.rb +0 -31
  22. data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
  23. data/examples/features/step_definitions/datamapper_steps.rb +0 -37
  24. data/examples/features/step_definitions/mongoid_steps.rb +0 -23
  25. data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
  26. data/examples/features/step_definitions/neo4j_steps.rb +0 -23
  27. data/examples/features/step_definitions/ohm_steps.rb +0 -31
  28. data/examples/features/step_definitions/redis_steps.rb +0 -31
  29. data/examples/features/step_definitions/translation_steps.rb +0 -55
  30. data/examples/features/support/env.rb +0 -61
  31. data/examples/lib/activerecord_models.rb +0 -41
  32. data/examples/lib/couchpotato_models.rb +0 -61
  33. data/examples/lib/datamapper_models.rb +0 -50
  34. data/examples/lib/mongoid_models.rb +0 -44
  35. data/examples/lib/mongomapper_models.rb +0 -51
  36. data/examples/lib/neo4j_models.rb +0 -17
  37. data/examples/lib/ohm_models.rb +0 -43
  38. data/examples/lib/redis_models.rb +0 -65
  39. data/examples/lib/sequel_models.rb +0 -9
  40. data/features/cleaning.feature +0 -30
  41. data/features/cleaning_default_strategy.feature +0 -23
  42. data/features/cleaning_multiple_dbs.feature +0 -22
  43. data/features/cleaning_multiple_orms.feature +0 -67
  44. data/features/step_definitions/database_cleaner_steps.rb +0 -33
  45. data/features/support/env.rb +0 -4
  46. data/features/support/feature_runner.rb +0 -39
  47. data/lib/database_cleaner/active_record/base.rb +0 -92
  48. data/lib/database_cleaner/active_record/deletion.rb +0 -106
  49. data/lib/database_cleaner/active_record/transaction.rb +0 -59
  50. data/lib/database_cleaner/active_record/truncation.rb +0 -275
  51. data/lib/database_cleaner/base.rb +0 -164
  52. data/lib/database_cleaner/configuration.rb +0 -131
  53. data/lib/database_cleaner/couch_potato/base.rb +0 -7
  54. data/lib/database_cleaner/couch_potato/truncation.rb +0 -28
  55. data/lib/database_cleaner/cucumber.rb +0 -3
  56. data/lib/database_cleaner/data_mapper/base.rb +0 -21
  57. data/lib/database_cleaner/data_mapper/transaction.rb +0 -28
  58. data/lib/database_cleaner/data_mapper/truncation.rb +0 -172
  59. data/lib/database_cleaner/generic/base.rb +0 -29
  60. data/lib/database_cleaner/generic/transaction.rb +0 -11
  61. data/lib/database_cleaner/generic/truncation.rb +0 -40
  62. data/lib/database_cleaner/mongo/base.rb +0 -16
  63. data/lib/database_cleaner/mongo/truncation.rb +0 -62
  64. data/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
  65. data/lib/database_cleaner/mongo2/base.rb +0 -16
  66. data/lib/database_cleaner/mongo2/truncation_mixin.rb +0 -39
  67. data/lib/database_cleaner/mongo_mapper/base.rb +0 -20
  68. data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
  69. data/lib/database_cleaner/mongoid/base.rb +0 -20
  70. data/lib/database_cleaner/mongoid/truncation.rb +0 -49
  71. data/lib/database_cleaner/moped/base.rb +0 -39
  72. data/lib/database_cleaner/moped/truncation.rb +0 -9
  73. data/lib/database_cleaner/moped/truncation_base.rb +0 -40
  74. data/lib/database_cleaner/neo4j/base.rb +0 -62
  75. data/lib/database_cleaner/neo4j/deletion.rb +0 -16
  76. data/lib/database_cleaner/neo4j/transaction.rb +0 -35
  77. data/lib/database_cleaner/neo4j/truncation.rb +0 -9
  78. data/lib/database_cleaner/null_strategy.rb +0 -20
  79. data/lib/database_cleaner/ohm/truncation.rb +0 -15
  80. data/lib/database_cleaner/redis/base.rb +0 -37
  81. data/lib/database_cleaner/redis/truncation.rb +0 -26
  82. data/lib/database_cleaner/sequel/base.rb +0 -22
  83. data/lib/database_cleaner/sequel/deletion.rb +0 -47
  84. data/lib/database_cleaner/sequel/transaction.rb +0 -40
  85. data/lib/database_cleaner/sequel/truncation.rb +0 -78
  86. data/spec/database_cleaner/active_record/base_spec.rb +0 -188
  87. data/spec/database_cleaner/active_record/transaction_spec.rb +0 -176
  88. data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +0 -38
  89. data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +0 -38
  90. data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +0 -75
  91. data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +0 -40
  92. data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +0 -40
  93. data/spec/database_cleaner/active_record/truncation_spec.rb +0 -180
  94. data/spec/database_cleaner/base_spec.rb +0 -617
  95. data/spec/database_cleaner/configuration_spec.rb +0 -345
  96. data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
  97. data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
  98. data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
  99. data/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +0 -41
  100. data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
  101. data/spec/database_cleaner/generic/base_spec.rb +0 -61
  102. data/spec/database_cleaner/generic/truncation_spec.rb +0 -118
  103. data/spec/database_cleaner/mongo/mongo_examples.rb +0 -26
  104. data/spec/database_cleaner/mongo/truncation_spec.rb +0 -72
  105. data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
  106. data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
  107. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
  108. data/spec/database_cleaner/moped/moped_examples.rb +0 -32
  109. data/spec/database_cleaner/moped/truncation_spec.rb +0 -80
  110. data/spec/database_cleaner/neo4j/base_spec.rb +0 -43
  111. data/spec/database_cleaner/neo4j/transaction_spec.rb +0 -25
  112. data/spec/database_cleaner/null_strategy_spec.rb +0 -28
  113. data/spec/database_cleaner/ohm/truncation_spec.rb +0 -70
  114. data/spec/database_cleaner/redis/base_spec.rb +0 -43
  115. data/spec/database_cleaner/redis/truncation_spec.rb +0 -63
  116. data/spec/database_cleaner/sequel/base_spec.rb +0 -32
  117. data/spec/database_cleaner/sequel/deletion_spec.rb +0 -58
  118. data/spec/database_cleaner/sequel/transaction_spec.rb +0 -21
  119. data/spec/database_cleaner/sequel/truncation/sqlite3_spec.rb +0 -0
  120. data/spec/database_cleaner/sequel/truncation_spec.rb +0 -182
  121. data/spec/database_cleaner/shared_strategy.rb +0 -15
  122. data/spec/rcov.opts +0 -1
  123. data/spec/spec_helper.rb +0 -21
  124. data/spec/support/active_record/database_setup.rb +0 -6
  125. data/spec/support/active_record/migrations/20150101010000_create_users.rb +0 -14
  126. data/spec/support/active_record/migrations/20150101020000_create_agents.rb +0 -14
  127. data/spec/support/active_record/mysql2_setup.rb +0 -39
  128. data/spec/support/active_record/mysql_setup.rb +0 -38
  129. data/spec/support/active_record/postgresql_setup.rb +0 -48
  130. data/spec/support/active_record/schema_setup.rb +0 -17
  131. data/spec/support/active_record/sqlite3_setup.rb +0 -40
  132. data/spec/support/data_mapper/schema_setup.rb +0 -15
  133. data/spec/support/data_mapper/sqlite3_setup.rb +0 -39
@@ -1,617 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'database_cleaner/active_record/transaction'
3
- require 'database_cleaner/data_mapper/transaction'
4
- require 'database_cleaner/mongo_mapper/truncation'
5
- require 'database_cleaner/mongoid/truncation'
6
- require 'database_cleaner/couch_potato/truncation'
7
- require 'database_cleaner/neo4j/transaction'
8
-
9
- module DatabaseCleaner
10
- describe Base do
11
-
12
- let(:mock_strategy) {
13
- double("strategy").tap{|strategy|
14
- strategy.stub(:to_ary => [strategy])
15
- }
16
- }
17
-
18
- describe "autodetect" do
19
-
20
- #Cache all ORMs, we'll need them later but not now.
21
- before(:all) do
22
- Temp_AR = ::ActiveRecord if defined?(::ActiveRecord) and not defined?(Temp_AR)
23
- Temp_DM = ::DataMapper if defined?(::DataMapper) and not defined?(Temp_DM)
24
- Temp_MM = ::MongoMapper if defined?(::MongoMapper) and not defined?(Temp_MM)
25
- Temp_MO = ::Mongoid if defined?(::Mongoid) and not defined?(Temp_MO)
26
- Temp_CP = ::CouchPotato if defined?(::CouchPotato) and not defined?(Temp_CP)
27
- Temp_SQ = ::Sequel if defined?(::Sequel) and not defined?(Temp_SQ)
28
- Temp_MP = ::Moped if defined?(::Moped) and not defined?(Temp_MP)
29
- Temp_RS = ::Redis if defined?(::Redis) and not defined?(Temp_RS)
30
- Temp_OH = ::Ohm if defined?(::Ohm) and not defined?(Temp_OH)
31
- Temp_NJ = ::Neo4j if defined?(::Neo4j) and not defined?(Temp_NJ)
32
- end
33
-
34
- #Remove all ORM mocks and restore from cache
35
- after(:all) do
36
- Object.send(:remove_const, 'ActiveRecord') if defined?(::ActiveRecord)
37
- Object.send(:remove_const, 'DataMapper') if defined?(::DataMapper)
38
- Object.send(:remove_const, 'MongoMapper') if defined?(::MongoMapper)
39
- Object.send(:remove_const, 'Mongoid') if defined?(::Mongoid)
40
- Object.send(:remove_const, 'CouchPotato') if defined?(::CouchPotato)
41
- Object.send(:remove_const, 'Sequel') if defined?(::Sequel)
42
- Object.send(:remove_const, 'Moped') if defined?(::Moped)
43
- Object.send(:remove_const, 'Ohm') if defined?(::Ohm)
44
- Object.send(:remove_const, 'Redis') if defined?(::Redis)
45
- Object.send(:remove_const, 'Neo4j') if defined?(::Neo4j)
46
-
47
-
48
- # Restore ORMs
49
- ::ActiveRecord = Temp_AR if defined? Temp_AR
50
- ::DataMapper = Temp_DM if defined? Temp_DM
51
- ::MongoMapper = Temp_MM if defined? Temp_MM
52
- ::Mongoid = Temp_MO if defined? Temp_MO
53
- ::CouchPotato = Temp_CP if defined? Temp_CP
54
- ::Sequel = Temp_SQ if defined? Temp_SQ
55
- ::Moped = Temp_MP if defined? Temp_MP
56
- ::Ohm = Temp_OH if defined? Temp_OH
57
- ::Redis = Temp_RS if defined? Temp_RS
58
- ::Neo4j = Temp_NJ if defined? Temp_NJ
59
- end
60
-
61
- #reset the orm mocks
62
- before(:each) do
63
- Object.send(:remove_const, 'ActiveRecord') if defined?(::ActiveRecord)
64
- Object.send(:remove_const, 'DataMapper') if defined?(::DataMapper)
65
- Object.send(:remove_const, 'MongoMapper') if defined?(::MongoMapper)
66
- Object.send(:remove_const, 'Mongoid') if defined?(::Mongoid)
67
- Object.send(:remove_const, 'CouchPotato') if defined?(::CouchPotato)
68
- Object.send(:remove_const, 'Sequel') if defined?(::Sequel)
69
- Object.send(:remove_const, 'Moped') if defined?(::Moped)
70
- Object.send(:remove_const, 'Ohm') if defined?(::Ohm)
71
- Object.send(:remove_const, 'Redis') if defined?(::Redis)
72
- Object.send(:remove_const, 'Neo4j') if defined?(::Neo4j)
73
- end
74
-
75
- let(:cleaner) { DatabaseCleaner::Base.new :autodetect }
76
-
77
- it "should raise an error when no ORM is detected" do
78
- running { cleaner }.should raise_error(DatabaseCleaner::NoORMDetected)
79
- end
80
-
81
- it "should detect ActiveRecord first" do
82
- Object.const_set('ActiveRecord','Actively mocking records.')
83
- Object.const_set('DataMapper', 'Mapping data mocks')
84
- Object.const_set('MongoMapper', 'Mapping mock mongos')
85
- Object.const_set('Mongoid', 'Mongoid mock')
86
- Object.const_set('CouchPotato', 'Couching mock potatos')
87
- Object.const_set('Sequel', 'Sequel mock')
88
- Object.const_set('Moped', 'Moped mock')
89
- Object.const_set('Ohm', 'Ohm mock')
90
- Object.const_set('Redis', 'Redis mock')
91
- Object.const_set('Neo4j', 'Neo4j mock')
92
-
93
- cleaner.orm.should eq :active_record
94
- cleaner.should be_auto_detected
95
- end
96
-
97
- it "should detect DataMapper second" do
98
- Object.const_set('DataMapper', 'Mapping data mocks')
99
- Object.const_set('MongoMapper', 'Mapping mock mongos')
100
- Object.const_set('Mongoid', 'Mongoid mock')
101
- Object.const_set('CouchPotato', 'Couching mock potatos')
102
- Object.const_set('Sequel', 'Sequel mock')
103
- Object.const_set('Moped', 'Moped mock')
104
- Object.const_set('Ohm', 'Ohm mock')
105
- Object.const_set('Redis', 'Redis mock')
106
- Object.const_set('Neo4j', 'Neo4j mock')
107
-
108
- cleaner.orm.should eq :data_mapper
109
- cleaner.should be_auto_detected
110
- end
111
-
112
- it "should detect MongoMapper third" do
113
- Object.const_set('MongoMapper', 'Mapping mock mongos')
114
- Object.const_set('Mongoid', 'Mongoid mock')
115
- Object.const_set('CouchPotato', 'Couching mock potatos')
116
- Object.const_set('Sequel', 'Sequel mock')
117
- Object.const_set('Moped', 'Moped mock')
118
- Object.const_set('Ohm', 'Ohm mock')
119
- Object.const_set('Redis', 'Redis mock')
120
- Object.const_set('Neo4j', 'Neo4j mock')
121
-
122
- cleaner.orm.should eq :mongo_mapper
123
- cleaner.should be_auto_detected
124
- end
125
-
126
- it "should detect Mongoid fourth" do
127
- Object.const_set('Mongoid', 'Mongoid mock')
128
- Object.const_set('CouchPotato', 'Couching mock potatos')
129
- Object.const_set('Sequel', 'Sequel mock')
130
- Object.const_set('Moped', 'Moped mock')
131
- Object.const_set('Ohm', 'Ohm mock')
132
- Object.const_set('Redis', 'Redis mock')
133
- Object.const_set('Neo4j', 'Neo4j mock')
134
-
135
- cleaner.orm.should eq :mongoid
136
- cleaner.should be_auto_detected
137
- end
138
-
139
- it "should detect CouchPotato fifth" do
140
- Object.const_set('CouchPotato', 'Couching mock potatos')
141
- Object.const_set('Sequel', 'Sequel mock')
142
- Object.const_set('Moped', 'Moped mock')
143
- Object.const_set('Ohm', 'Ohm mock')
144
- Object.const_set('Redis', 'Redis mock')
145
- Object.const_set('Neo4j', 'Neo4j mock')
146
-
147
- cleaner.orm.should eq :couch_potato
148
- cleaner.should be_auto_detected
149
- end
150
-
151
- it "should detect Sequel sixth" do
152
- Object.const_set('Sequel', 'Sequel mock')
153
- Object.const_set('Moped', 'Moped mock')
154
- Object.const_set('Ohm', 'Ohm mock')
155
- Object.const_set('Redis', 'Redis mock')
156
- Object.const_set('Neo4j', 'Neo4j mock')
157
-
158
- cleaner.orm.should eq :sequel
159
- cleaner.should be_auto_detected
160
- end
161
-
162
- it 'detects Moped seventh' do
163
- Object.const_set('Moped', 'Moped mock')
164
-
165
- cleaner.orm.should eq :moped
166
- cleaner.should be_auto_detected
167
- end
168
-
169
- it 'detects Ohm eighth' do
170
- Object.const_set('Ohm', 'Ohm mock')
171
- Object.const_set('Redis', 'Redis mock')
172
- Object.const_set('Neo4j', 'Neo4j mock')
173
-
174
- cleaner.orm.should eq :ohm
175
- cleaner.should be_auto_detected
176
- end
177
-
178
- it 'detects Redis ninth' do
179
- Object.const_set('Redis', 'Redis mock')
180
- Object.const_set('Neo4j', 'Neo4j mock')
181
-
182
- cleaner.orm.should eq :redis
183
- cleaner.should be_auto_detected
184
- end
185
-
186
- it 'detects Neo4j tenth' do
187
- Object.const_set('Neo4j', 'Neo4j mock')
188
-
189
- cleaner.orm.should eq :neo4j
190
- cleaner.should be_auto_detected
191
- end
192
- end
193
-
194
- describe "orm_module" do
195
- it "should ask ::DatabaseCleaner what the module is for its orm" do
196
- orm = double("orm")
197
- mockule = double("module")
198
-
199
- cleaner = ::DatabaseCleaner::Base.new
200
- cleaner.should_receive(:orm).and_return(orm)
201
-
202
- ::DatabaseCleaner.should_receive(:orm_module).with(orm).and_return(mockule)
203
-
204
- cleaner.send(:orm_module).should eq mockule
205
- end
206
- end
207
-
208
- describe "comparison" do
209
- it "should be equal if orm, connection and strategy are the same" do
210
- one = DatabaseCleaner::Base.new(:active_record,:connection => :default)
211
- one.strategy = mock_strategy
212
-
213
- two = DatabaseCleaner::Base.new(:active_record,:connection => :default)
214
- two.strategy = mock_strategy
215
-
216
- one.should eq two
217
- two.should eq one
218
- end
219
-
220
- it "should not be equal if orm are not the same" do
221
- one = DatabaseCleaner::Base.new(:mongo_id, :connection => :default)
222
- one.strategy = mock_strategy
223
-
224
- two = DatabaseCleaner::Base.new(:active_record, :connection => :default)
225
- two.strategy = mock_strategy
226
-
227
- one.should_not eq two
228
- two.should_not eq one
229
- end
230
-
231
- it "should not be equal if connection are not the same" do
232
-
233
- one = DatabaseCleaner::Base.new(:active_record, :connection => :default)
234
- one.strategy = :truncation
235
-
236
- two = DatabaseCleaner::Base.new(:active_record, :connection => :other)
237
- two.strategy = :truncation
238
-
239
- one.should_not eq two
240
- two.should_not eq one
241
- end
242
- end
243
-
244
- describe "initialization" do
245
- context "db specified" do
246
- subject { ::DatabaseCleaner::Base.new(:active_record,:connection => :my_db) }
247
-
248
- it "should store db from :connection in params hash" do
249
- subject.db.should eq :my_db
250
- end
251
- end
252
-
253
- describe "orm" do
254
- it "should store orm" do
255
- cleaner = ::DatabaseCleaner::Base.new :a_orm
256
- cleaner.orm.should eq :a_orm
257
- end
258
-
259
- it "converts string to symbols" do
260
- cleaner = ::DatabaseCleaner::Base.new "mongoid"
261
- cleaner.orm.should eq :mongoid
262
- end
263
-
264
- it "is autodetected if orm is not provided" do
265
- cleaner = ::DatabaseCleaner::Base.new
266
- cleaner.should be_auto_detected
267
- end
268
-
269
- it "is autodetected if you specify :autodetect" do
270
- cleaner = ::DatabaseCleaner::Base.new "autodetect"
271
- cleaner.should be_auto_detected
272
- end
273
-
274
- it "should default to autodetect upon initalisation" do
275
- subject.should be_auto_detected
276
- end
277
- end
278
- end
279
-
280
- describe "db" do
281
- it "should default to :default" do
282
- subject.db.should eq :default
283
- end
284
-
285
- it "should return any stored db value" do
286
- subject.stub(:strategy_db=)
287
- subject.db = :test_db
288
- subject.db.should eq :test_db
289
- end
290
-
291
- it "should pass db to any specified strategy" do
292
- subject.should_receive(:strategy_db=).with(:a_new_db)
293
- subject.db = :a_new_db
294
- end
295
- end
296
-
297
- describe "strategy_db=" do
298
- let(:strategy) { mock_strategy }
299
-
300
- before(:each) do
301
- subject.strategy = strategy
302
- end
303
-
304
- it "should check that strategy supports db specification" do
305
- strategy.should_receive(:respond_to?).with(:db=).and_return(true)
306
- strategy.stub(:db=)
307
- subject.strategy_db = :a_db
308
- end
309
-
310
- context "when strategy supports db specification" do
311
- before(:each) { strategy.stub(:respond_to?).with(:db=).and_return true }
312
-
313
- it "should pass db to the strategy" do
314
- strategy.should_receive(:db=).with(:a_db)
315
- subject.strategy_db = :a_db
316
- end
317
- end
318
-
319
- context "when strategy doesn't supports db specification" do
320
- before(:each) { strategy.stub(:respond_to?).with(:db=).and_return false }
321
-
322
- it "should check to see if db is :default" do
323
- db = double("default")
324
- db.should_receive(:==).with(:default).and_return(true)
325
-
326
- subject.strategy_db = db
327
- end
328
-
329
- it "should raise an argument error when db isn't default" do
330
- db = double("a db")
331
- expect{ subject.strategy_db = db }.to raise_error ArgumentError
332
- end
333
- end
334
- end
335
-
336
- describe "clean_with" do
337
- let (:strategy) { double("strategy",:clean => true) }
338
-
339
- before(:each) { subject.stub(:create_strategy).with(anything).and_return(strategy) }
340
-
341
- it "should pass all arguments to create_strategy" do
342
- subject.should_receive(:create_strategy).with(:lorum, :dollar, :amet, :ipsum => "random").and_return(strategy)
343
- subject.clean_with :lorum, :dollar, :amet, { :ipsum => "random" }
344
- end
345
-
346
- it "should invoke clean on the created strategy" do
347
- strategy.should_receive(:clean)
348
- subject.clean_with :strategy
349
- end
350
-
351
- it "should return the strategy" do
352
- subject.clean_with( :strategy ).should eq strategy
353
- end
354
- end
355
-
356
- describe "clean_with!" do
357
- let (:strategy) { double("strategy",:clean => true) }
358
-
359
- before(:each) { subject.stub(:create_strategy).with(anything).and_return(strategy) }
360
-
361
- it "should pass all arguments to create_strategy" do
362
- subject.should_receive(:create_strategy).with(:lorum, :dollar, :amet, :ipsum => "random").and_return(strategy)
363
- subject.clean_with! :lorum, :dollar, :amet, { :ipsum => "random" }
364
- end
365
-
366
- it "should invoke clean on the created strategy" do
367
- strategy.should_receive(:clean)
368
- subject.clean_with! :strategy
369
- end
370
-
371
- it "should return the strategy" do
372
- subject.clean_with!( :strategy ).should eq strategy
373
- end
374
- end
375
-
376
- describe "create_strategy" do
377
- let(:strategy_class) { double("strategy_class",:new => double("instance")) }
378
-
379
- before :each do
380
- subject.stub(:orm_strategy).and_return(strategy_class)
381
- end
382
-
383
- it "should pass the first argument to orm_strategy" do
384
- subject.should_receive(:orm_strategy).with(:strategy).and_return(Object)
385
- subject.create_strategy :strategy
386
- end
387
- it "should pass the remainding argument to orm_strategy.new" do
388
- strategy_class.should_receive(:new).with(:params => {:lorum => "ipsum"})
389
-
390
- subject.create_strategy :strategy, {:params => {:lorum => "ipsum"}}
391
- end
392
- it "should return the resulting strategy" do
393
- subject.create_strategy( :strategy ).should eq strategy_class.new
394
- end
395
- end
396
-
397
- describe "strategy=" do
398
- it "should proxy symbolised strategies to create_strategy" do
399
- subject.should_receive(:create_strategy).with(:symbol)
400
- subject.strategy = :symbol
401
- end
402
-
403
- it "should proxy params with symbolised strategies" do
404
- subject.should_receive(:create_strategy).with(:symbol,:param => "one")
405
- subject.strategy= :symbol, {:param => "one"}
406
- end
407
-
408
- it "should accept strategy objects" do
409
- expect{ subject.strategy = mock_strategy }.to_not raise_error
410
- end
411
-
412
- it "should raise argument error when params given with strategy Object" do
413
- expect{ subject.strategy = double("object"), {:param => "one"} }.to raise_error ArgumentError
414
- end
415
-
416
- it "should attempt to set strategy db" do
417
- subject.stub(:db).and_return(:my_db)
418
- subject.should_receive(:set_strategy_db).with(mock_strategy, :my_db)
419
- subject.strategy = mock_strategy
420
- end
421
-
422
- it "should return the stored strategy" do
423
- result = subject.strategy = mock_strategy
424
- result.should eq mock_strategy
425
- end
426
- end
427
-
428
- describe "strategy" do
429
- subject { ::DatabaseCleaner::Base.new :a_orm }
430
-
431
- it "returns a null strategy when strategy is not set and undetectable" do
432
- subject.strategy.should eq DatabaseCleaner::NullStrategy
433
- end
434
-
435
- it "returns the set strategy" do
436
- subject.strategy = mock_strategy
437
- subject.strategy.should eq mock_strategy
438
- end
439
- end
440
-
441
- describe "orm=" do
442
- it "should stored the desired orm" do
443
- subject.orm.should_not eq :desired_orm
444
- subject.orm = :desired_orm
445
- subject.orm.should eq :desired_orm
446
- end
447
- end
448
-
449
- describe "orm" do
450
- let(:mock_orm) { double("orm") }
451
-
452
- it "should return orm if orm set" do
453
- subject.instance_variable_set "@orm", mock_orm
454
- subject.orm.should eq mock_orm
455
- end
456
-
457
- context "orm isn't set" do
458
- before(:each) { subject.instance_variable_set "@orm", nil }
459
-
460
- it "should run autodetect if orm isn't set" do
461
- subject.should_receive(:autodetect)
462
- subject.orm
463
- end
464
-
465
- it "should return the result of autodetect if orm isn't set" do
466
- subject.stub(:autodetect).and_return(mock_orm)
467
- subject.orm.should eq mock_orm
468
- end
469
- end
470
- end
471
-
472
- describe "proxy methods" do
473
- let (:strategy) { double("strategy") }
474
-
475
- before(:each) do
476
- subject.stub(:strategy).and_return(strategy)
477
- end
478
-
479
- describe "start" do
480
- it "should proxy start to the strategy" do
481
- strategy.should_receive(:start)
482
- subject.start
483
- end
484
- end
485
-
486
- describe "clean" do
487
- it "should proxy clean to the strategy" do
488
- strategy.should_receive(:clean)
489
- subject.clean
490
- end
491
- end
492
-
493
- describe "clean!" do
494
- it "should proxy clean! to the strategy clean" do
495
- strategy.should_receive(:clean)
496
- subject.clean!
497
- end
498
- end
499
-
500
- describe "cleaning" do
501
- it "should proxy cleaning to the strategy" do
502
- strategy.should_receive(:cleaning)
503
- subject.cleaning { }
504
- end
505
- end
506
- end
507
-
508
- describe "auto_detected?" do
509
- it "should return true unless @autodetected is nil" do
510
- subject.instance_variable_set("@autodetected","not nil")
511
- subject.auto_detected?.should be_true
512
- end
513
-
514
- it "should return false if @autodetect is nil" do
515
- subject.instance_variable_set("@autodetected",nil)
516
- subject.auto_detected?.should be_false
517
- end
518
- end
519
-
520
- describe "orm_strategy" do
521
- let (:strategy_class) { double("strategy_class") }
522
-
523
- before(:each) do
524
- subject.stub(:orm_module).and_return(strategy_class)
525
- end
526
-
527
- context "in response to a LoadError" do
528
- before(:each) { subject.should_receive(:require).with(anything).and_raise(LoadError) }
529
-
530
- it "should raise UnknownStrategySpecified" do
531
- expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
532
- end
533
-
534
- it "should ask orm_module if it will list available_strategies" do
535
- strategy_class.should_receive(:respond_to?).with(:available_strategies)
536
-
537
- subject.stub(:orm_module).and_return(strategy_class)
538
-
539
- expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
540
- end
541
-
542
- it "should use available_strategies (for the error message) if its available" do
543
- strategy_class.stub(:respond_to?).with(:available_strategies).and_return(true)
544
- strategy_class.should_receive(:available_strategies).and_return([])
545
-
546
- subject.stub(:orm_module).and_return(strategy_class)
547
-
548
- expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
549
- end
550
- end
551
-
552
- it "should return the constant of the Strategy class requested" do
553
- strategy_strategy_class = double("strategy strategy_class")
554
-
555
- subject.stub(:require).with(anything).and_return(true)
556
-
557
- strategy_class.should_receive(:const_get).with("Cunningplan").and_return(strategy_strategy_class)
558
-
559
- subject.send(:orm_strategy, :cunningplan).should eq strategy_strategy_class
560
- end
561
-
562
- end
563
-
564
- describe 'set_default_orm_strategy' do
565
- it 'sets strategy to :transaction for ActiveRecord' do
566
- cleaner = DatabaseCleaner::Base.new(:active_record)
567
- cleaner.strategy.should be_instance_of DatabaseCleaner::ActiveRecord::Transaction
568
- end
569
-
570
- it 'sets strategy to :transaction for DataMapper' do
571
- cleaner = DatabaseCleaner::Base.new(:data_mapper)
572
- cleaner.strategy.should be_instance_of DatabaseCleaner::DataMapper::Transaction
573
- end
574
-
575
- it 'sets strategy to :truncation for MongoMapper' do
576
- cleaner = DatabaseCleaner::Base.new(:mongo_mapper)
577
- cleaner.strategy.should be_instance_of DatabaseCleaner::MongoMapper::Truncation
578
- end
579
-
580
- it 'sets strategy to :truncation for Mongoid' do
581
- cleaner = DatabaseCleaner::Base.new(:mongoid)
582
- cleaner.strategy.should be_instance_of DatabaseCleaner::Mongoid::Truncation
583
- end
584
-
585
- it 'sets strategy to :truncation for CouchPotato' do
586
- cleaner = DatabaseCleaner::Base.new(:couch_potato)
587
- cleaner.strategy.should be_instance_of DatabaseCleaner::CouchPotato::Truncation
588
- end
589
-
590
- it 'sets strategy to :transaction for Sequel' do
591
- cleaner = DatabaseCleaner::Base.new(:sequel)
592
- cleaner.strategy.should be_instance_of DatabaseCleaner::Sequel::Transaction
593
- end
594
-
595
- it 'sets strategy to :truncation for Moped' do
596
- cleaner = DatabaseCleaner::Base.new(:moped)
597
- cleaner.strategy.should be_instance_of DatabaseCleaner::Moped::Truncation
598
- end
599
-
600
- it 'sets strategy to :truncation for Ohm' do
601
- cleaner = DatabaseCleaner::Base.new(:ohm)
602
- cleaner.strategy.should be_instance_of DatabaseCleaner::Ohm::Truncation
603
- end
604
-
605
- it 'sets strategy to :truncation for Redis' do
606
- cleaner = DatabaseCleaner::Base.new(:redis)
607
- cleaner.strategy.should be_instance_of DatabaseCleaner::Redis::Truncation
608
- end
609
-
610
- it 'sets strategy to :transaction for Neo4j' do
611
- cleaner = DatabaseCleaner::Base.new(:neo4j)
612
- cleaner.strategy.should be_instance_of DatabaseCleaner::Neo4j::Transaction
613
- end
614
- end
615
-
616
- end
617
- end