database_cleaner 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +12 -12
- data/History.rdoc +17 -0
- data/README.markdown +4 -0
- data/Rakefile +1 -0
- data/VERSION.yml +2 -2
- data/examples/Gemfile.lock +12 -12
- data/lib/database_cleaner/active_record/base.rb +3 -3
- data/lib/database_cleaner/active_record/deletion.rb +19 -36
- data/lib/database_cleaner/active_record/truncation.rb +40 -67
- data/lib/database_cleaner/base.rb +3 -3
- data/lib/database_cleaner/configuration.rb +1 -1
- data/lib/database_cleaner/data_mapper/base.rb +1 -1
- data/lib/database_cleaner/data_mapper/truncation.rb +22 -2
- data/lib/database_cleaner/generic/truncation.rb +4 -3
- data/lib/database_cleaner/mongo_mapper/base.rb +1 -1
- data/lib/database_cleaner/moped/base.rb +2 -2
- data/lib/database_cleaner/redis/base.rb +1 -1
- data/spec/database_cleaner/active_record/base_spec.rb +10 -10
- data/spec/database_cleaner/active_record/transaction_spec.rb +1 -1
- data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +42 -0
- data/spec/database_cleaner/active_record/truncation_spec.rb +50 -29
- data/spec/database_cleaner/base_spec.rb +44 -48
- data/spec/database_cleaner/configuration_spec.rb +74 -74
- data/spec/database_cleaner/couch_potato/truncation_spec.rb +2 -2
- data/spec/database_cleaner/data_mapper/base_spec.rb +2 -2
- data/spec/database_cleaner/generic/base_spec.rb +1 -1
- data/spec/database_cleaner/generic/truncation_spec.rb +26 -16
- data/spec/database_cleaner/mongo_mapper/base_spec.rb +2 -2
- data/spec/database_cleaner/moped/truncation_spec.rb +1 -1
- data/spec/database_cleaner/ohm/truncation_spec.rb +8 -8
- data/spec/database_cleaner/redis/base_spec.rb +2 -2
- data/spec/database_cleaner/redis/truncation_spec.rb +8 -8
- data/spec/database_cleaner/sequel/base_spec.rb +2 -2
- data/spec/support/active_record/sqlite3_setup.rb +40 -0
- metadata +4 -2
@@ -77,7 +77,7 @@ module DatabaseCleaner
|
|
77
77
|
Object.const_set('Ohm', 'Ohm mock')
|
78
78
|
Object.const_set('Redis', 'Redis mock')
|
79
79
|
|
80
|
-
cleaner.orm.should
|
80
|
+
cleaner.orm.should eq :active_record
|
81
81
|
cleaner.should be_auto_detected
|
82
82
|
end
|
83
83
|
|
@@ -91,7 +91,7 @@ module DatabaseCleaner
|
|
91
91
|
Object.const_set('Ohm', 'Ohm mock')
|
92
92
|
Object.const_set('Redis', 'Redis mock')
|
93
93
|
|
94
|
-
cleaner.orm.should
|
94
|
+
cleaner.orm.should eq :data_mapper
|
95
95
|
cleaner.should be_auto_detected
|
96
96
|
end
|
97
97
|
|
@@ -104,7 +104,7 @@ module DatabaseCleaner
|
|
104
104
|
Object.const_set('Ohm', 'Ohm mock')
|
105
105
|
Object.const_set('Redis', 'Redis mock')
|
106
106
|
|
107
|
-
cleaner.orm.should
|
107
|
+
cleaner.orm.should eq :mongo_mapper
|
108
108
|
cleaner.should be_auto_detected
|
109
109
|
end
|
110
110
|
|
@@ -116,7 +116,7 @@ module DatabaseCleaner
|
|
116
116
|
Object.const_set('Ohm', 'Ohm mock')
|
117
117
|
Object.const_set('Redis', 'Redis mock')
|
118
118
|
|
119
|
-
cleaner.orm.should
|
119
|
+
cleaner.orm.should eq :mongoid
|
120
120
|
cleaner.should be_auto_detected
|
121
121
|
end
|
122
122
|
|
@@ -127,7 +127,7 @@ module DatabaseCleaner
|
|
127
127
|
Object.const_set('Ohm', 'Ohm mock')
|
128
128
|
Object.const_set('Redis', 'Redis mock')
|
129
129
|
|
130
|
-
cleaner.orm.should
|
130
|
+
cleaner.orm.should eq :couch_potato
|
131
131
|
cleaner.should be_auto_detected
|
132
132
|
end
|
133
133
|
|
@@ -137,7 +137,7 @@ module DatabaseCleaner
|
|
137
137
|
Object.const_set('Ohm', 'Ohm mock')
|
138
138
|
Object.const_set('Redis', 'Redis mock')
|
139
139
|
|
140
|
-
cleaner.orm.should
|
140
|
+
cleaner.orm.should eq :sequel
|
141
141
|
cleaner.should be_auto_detected
|
142
142
|
end
|
143
143
|
|
@@ -145,42 +145,42 @@ module DatabaseCleaner
|
|
145
145
|
Object.const_set('Ohm', 'Ohm mock')
|
146
146
|
Object.const_set('Redis', 'Redis mock')
|
147
147
|
|
148
|
-
cleaner.orm.should
|
148
|
+
cleaner.orm.should eq :ohm
|
149
149
|
cleaner.should be_auto_detected
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'detects Redis last' do
|
153
153
|
Object.const_set('Redis', 'Redis mock')
|
154
154
|
|
155
|
-
cleaner.orm.should
|
155
|
+
cleaner.orm.should eq :redis
|
156
156
|
cleaner.should be_auto_detected
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'detects Moped seventh' do
|
160
160
|
Object.const_set('Moped', 'Moped mock')
|
161
161
|
|
162
|
-
cleaner.orm.should
|
162
|
+
cleaner.orm.should eq :moped
|
163
163
|
cleaner.should be_auto_detected
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
167
|
describe "orm_module" do
|
168
168
|
it "should ask ::DatabaseCleaner what the module is for its orm" do
|
169
|
-
orm =
|
170
|
-
mockule =
|
169
|
+
orm = double("orm")
|
170
|
+
mockule = double("module")
|
171
171
|
|
172
172
|
cleaner = ::DatabaseCleaner::Base.new
|
173
173
|
cleaner.should_receive(:orm).and_return(orm)
|
174
174
|
|
175
175
|
::DatabaseCleaner.should_receive(:orm_module).with(orm).and_return(mockule)
|
176
176
|
|
177
|
-
cleaner.send(:orm_module).should
|
177
|
+
cleaner.send(:orm_module).should eq mockule
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
181
|
describe "comparison" do
|
182
182
|
it "should be equal if orm, connection and strategy are the same" do
|
183
|
-
strategy =
|
183
|
+
strategy = double("strategy")
|
184
184
|
|
185
185
|
one = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
186
186
|
one.strategy = strategy
|
@@ -188,8 +188,8 @@ module DatabaseCleaner
|
|
188
188
|
two = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
189
189
|
two.strategy = strategy
|
190
190
|
|
191
|
-
one.should
|
192
|
-
two.should
|
191
|
+
one.should eq two
|
192
|
+
two.should eq one
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
@@ -198,19 +198,19 @@ module DatabaseCleaner
|
|
198
198
|
subject { ::DatabaseCleaner::Base.new(:active_record,:connection => :my_db) }
|
199
199
|
|
200
200
|
it "should store db from :connection in params hash" do
|
201
|
-
subject.db.should
|
201
|
+
subject.db.should eq :my_db
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
205
|
describe "orm" do
|
206
206
|
it "should store orm" do
|
207
207
|
cleaner = ::DatabaseCleaner::Base.new :a_orm
|
208
|
-
cleaner.orm.should
|
208
|
+
cleaner.orm.should eq :a_orm
|
209
209
|
end
|
210
210
|
|
211
211
|
it "converts string to symbols" do
|
212
212
|
cleaner = ::DatabaseCleaner::Base.new "mongoid"
|
213
|
-
cleaner.orm.should
|
213
|
+
cleaner.orm.should eq :mongoid
|
214
214
|
end
|
215
215
|
|
216
216
|
it "is autodetected if orm is not provided" do
|
@@ -231,13 +231,13 @@ module DatabaseCleaner
|
|
231
231
|
|
232
232
|
describe "db" do
|
233
233
|
it "should default to :default" do
|
234
|
-
subject.db.should
|
234
|
+
subject.db.should eq :default
|
235
235
|
end
|
236
236
|
|
237
237
|
it "should return any stored db value" do
|
238
238
|
subject.stub(:strategy_db=)
|
239
239
|
subject.db = :test_db
|
240
|
-
subject.db.should
|
240
|
+
subject.db.should eq :test_db
|
241
241
|
end
|
242
242
|
|
243
243
|
it "should pass db to any specified strategy" do
|
@@ -247,7 +247,7 @@ module DatabaseCleaner
|
|
247
247
|
end
|
248
248
|
|
249
249
|
describe "strategy_db=" do
|
250
|
-
let(:strategy) {
|
250
|
+
let(:strategy) { double("strategy") }
|
251
251
|
|
252
252
|
before(:each) do
|
253
253
|
subject.strategy = strategy
|
@@ -272,21 +272,21 @@ module DatabaseCleaner
|
|
272
272
|
before(:each) { strategy.stub(:respond_to?).with(:db=).and_return false }
|
273
273
|
|
274
274
|
it "should check to see if db is :default" do
|
275
|
-
db =
|
275
|
+
db = double("default")
|
276
276
|
db.should_receive(:==).with(:default).and_return(true)
|
277
277
|
|
278
278
|
subject.strategy_db = db
|
279
279
|
end
|
280
280
|
|
281
281
|
it "should raise an argument error when db isn't default" do
|
282
|
-
db =
|
282
|
+
db = double("a db")
|
283
283
|
expect{ subject.strategy_db = db }.to raise_error ArgumentError
|
284
284
|
end
|
285
285
|
end
|
286
286
|
end
|
287
287
|
|
288
288
|
describe "clean_with" do
|
289
|
-
let (:strategy) {
|
289
|
+
let (:strategy) { double("strategy",:clean => true) }
|
290
290
|
|
291
291
|
before(:each) { subject.stub(:create_strategy).with(anything).and_return(strategy) }
|
292
292
|
|
@@ -301,12 +301,12 @@ module DatabaseCleaner
|
|
301
301
|
end
|
302
302
|
|
303
303
|
it "should return the strategy" do
|
304
|
-
subject.clean_with( :strategy ).should
|
304
|
+
subject.clean_with( :strategy ).should eq strategy
|
305
305
|
end
|
306
306
|
end
|
307
307
|
|
308
308
|
describe "clean_with!" do
|
309
|
-
let (:strategy) {
|
309
|
+
let (:strategy) { double("strategy",:clean => true) }
|
310
310
|
|
311
311
|
before(:each) { subject.stub(:create_strategy).with(anything).and_return(strategy) }
|
312
312
|
|
@@ -321,12 +321,12 @@ module DatabaseCleaner
|
|
321
321
|
end
|
322
322
|
|
323
323
|
it "should return the strategy" do
|
324
|
-
subject.clean_with!( :strategy ).should
|
324
|
+
subject.clean_with!( :strategy ).should eq strategy
|
325
325
|
end
|
326
326
|
end
|
327
327
|
|
328
328
|
describe "create_strategy" do
|
329
|
-
let(:strategy_class) {
|
329
|
+
let(:strategy_class) { double("strategy_class",:new => double("instance")) }
|
330
330
|
|
331
331
|
before :each do
|
332
332
|
subject.stub(:orm_strategy).and_return(strategy_class)
|
@@ -342,12 +342,12 @@ module DatabaseCleaner
|
|
342
342
|
subject.create_strategy :strategy, {:params => {:lorum => "ipsum"}}
|
343
343
|
end
|
344
344
|
it "should return the resulting strategy" do
|
345
|
-
subject.create_strategy( :strategy ).should
|
345
|
+
subject.create_strategy( :strategy ).should eq strategy_class.new
|
346
346
|
end
|
347
347
|
end
|
348
348
|
|
349
349
|
describe "strategy=" do
|
350
|
-
let(:mock_strategy) {
|
350
|
+
let(:mock_strategy) { double("strategy") }
|
351
351
|
|
352
352
|
it "should proxy symbolised strategies to create_strategy" do
|
353
353
|
subject.should_receive(:create_strategy).with(:symbol)
|
@@ -364,7 +364,7 @@ module DatabaseCleaner
|
|
364
364
|
end
|
365
365
|
|
366
366
|
it "should raise argument error when params given with strategy Object" do
|
367
|
-
expect{ subject.strategy =
|
367
|
+
expect{ subject.strategy = double("object"), {:param => "one"} }.to raise_error ArgumentError
|
368
368
|
end
|
369
369
|
|
370
370
|
it "should attempt to set strategy db" do
|
@@ -375,7 +375,7 @@ module DatabaseCleaner
|
|
375
375
|
|
376
376
|
it "should return the stored strategy" do
|
377
377
|
result = subject.strategy = mock_strategy
|
378
|
-
result.should
|
378
|
+
result.should eq mock_strategy
|
379
379
|
end
|
380
380
|
end
|
381
381
|
|
@@ -383,30 +383,30 @@ module DatabaseCleaner
|
|
383
383
|
subject { ::DatabaseCleaner::Base.new :a_orm }
|
384
384
|
|
385
385
|
it "returns a null strategy when strategy is not set and undetectable" do
|
386
|
-
subject.strategy.should
|
386
|
+
subject.strategy.should eq DatabaseCleaner::NullStrategy
|
387
387
|
end
|
388
388
|
|
389
389
|
it "returns the set strategy" do
|
390
|
-
strategum =
|
390
|
+
strategum = double("strategy")
|
391
391
|
subject.strategy = strategum
|
392
|
-
subject.strategy.should
|
392
|
+
subject.strategy.should eq strategum
|
393
393
|
end
|
394
394
|
end
|
395
395
|
|
396
396
|
describe "orm=" do
|
397
397
|
it "should stored the desired orm" do
|
398
|
-
subject.orm.should_not
|
398
|
+
subject.orm.should_not eq :desired_orm
|
399
399
|
subject.orm = :desired_orm
|
400
|
-
subject.orm.should
|
400
|
+
subject.orm.should eq :desired_orm
|
401
401
|
end
|
402
402
|
end
|
403
403
|
|
404
404
|
describe "orm" do
|
405
|
-
let(:mock_orm) {
|
405
|
+
let(:mock_orm) { double("orm") }
|
406
406
|
|
407
407
|
it "should return orm if orm set" do
|
408
408
|
subject.instance_variable_set "@orm", mock_orm
|
409
|
-
subject.orm.should
|
409
|
+
subject.orm.should eq mock_orm
|
410
410
|
end
|
411
411
|
|
412
412
|
context "orm isn't set" do
|
@@ -419,13 +419,13 @@ module DatabaseCleaner
|
|
419
419
|
|
420
420
|
it "should return the result of autodetect if orm isn't set" do
|
421
421
|
subject.stub(:autodetect).and_return(mock_orm)
|
422
|
-
subject.orm.should
|
422
|
+
subject.orm.should eq mock_orm
|
423
423
|
end
|
424
424
|
end
|
425
425
|
end
|
426
426
|
|
427
427
|
describe "proxy methods" do
|
428
|
-
let (:strategy) {
|
428
|
+
let (:strategy) { double("strategy") }
|
429
429
|
|
430
430
|
before(:each) do
|
431
431
|
subject.stub(:strategy).and_return(strategy)
|
@@ -466,7 +466,7 @@ module DatabaseCleaner
|
|
466
466
|
end
|
467
467
|
|
468
468
|
describe "orm_strategy" do
|
469
|
-
let (:strategy_class) {
|
469
|
+
let (:strategy_class) { double("strategy_class") }
|
470
470
|
|
471
471
|
before(:each) do
|
472
472
|
subject.stub(:orm_module).and_return(strategy_class)
|
@@ -475,10 +475,6 @@ module DatabaseCleaner
|
|
475
475
|
context "in response to a LoadError" do
|
476
476
|
before(:each) { subject.should_receive(:require).with(anything).and_raise(LoadError) }
|
477
477
|
|
478
|
-
it "should catch LoadErrors" do
|
479
|
-
expect { subject.send(:orm_strategy,:a_strategy) }.to_not raise_error LoadError
|
480
|
-
end
|
481
|
-
|
482
478
|
it "should raise UnknownStrategySpecified" do
|
483
479
|
expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
|
484
480
|
end
|
@@ -502,13 +498,13 @@ module DatabaseCleaner
|
|
502
498
|
end
|
503
499
|
|
504
500
|
it "should return the constant of the Strategy class requested" do
|
505
|
-
strategy_strategy_class =
|
501
|
+
strategy_strategy_class = double("strategy strategy_class")
|
506
502
|
|
507
503
|
subject.stub(:require).with(anything).and_return(true)
|
508
504
|
|
509
505
|
strategy_class.should_receive(:const_get).with("Cunningplan").and_return(strategy_strategy_class)
|
510
506
|
|
511
|
-
subject.send(:orm_strategy, :cunningplan).should
|
507
|
+
subject.send(:orm_strategy, :cunningplan).should eq strategy_strategy_class
|
512
508
|
end
|
513
509
|
|
514
510
|
end
|
@@ -13,7 +13,7 @@ module DatabaseCleaner
|
|
13
13
|
@connections = nil
|
14
14
|
end
|
15
15
|
# hackey, hack.. connections needs to stick around until I can properly deprecate the API
|
16
|
-
def connections_stub
|
16
|
+
def connections_stub(array)
|
17
17
|
@cleaners = ArrayHelper.zipmap((1..array.size).to_a, array)
|
18
18
|
@connections = array
|
19
19
|
end
|
@@ -31,70 +31,70 @@ describe ::DatabaseCleaner do
|
|
31
31
|
it "should accept :active_record" do
|
32
32
|
cleaner = ::DatabaseCleaner[:active_record]
|
33
33
|
cleaner.should be_a(::DatabaseCleaner::Base)
|
34
|
-
cleaner.orm.should
|
35
|
-
::DatabaseCleaner.connections.size.should
|
34
|
+
cleaner.orm.should eq :active_record
|
35
|
+
::DatabaseCleaner.connections.size.should eq 1
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should accept :data_mapper" do
|
39
39
|
cleaner = ::DatabaseCleaner[:data_mapper]
|
40
40
|
cleaner.should be_a(::DatabaseCleaner::Base)
|
41
|
-
cleaner.orm.should
|
42
|
-
::DatabaseCleaner.connections.size.should
|
41
|
+
cleaner.orm.should eq :data_mapper
|
42
|
+
::DatabaseCleaner.connections.size.should eq 1
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should accept :mongo_mapper" do
|
46
46
|
cleaner = ::DatabaseCleaner[:mongo_mapper]
|
47
47
|
cleaner.should be_a(::DatabaseCleaner::Base)
|
48
|
-
cleaner.orm.should
|
49
|
-
::DatabaseCleaner.connections.size.should
|
48
|
+
cleaner.orm.should eq :mongo_mapper
|
49
|
+
::DatabaseCleaner.connections.size.should eq 1
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should accept :couch_potato" do
|
53
53
|
cleaner = ::DatabaseCleaner[:couch_potato]
|
54
54
|
cleaner.should be_a(::DatabaseCleaner::Base)
|
55
|
-
cleaner.orm.should
|
56
|
-
::DatabaseCleaner.connections.size.should
|
55
|
+
cleaner.orm.should eq :couch_potato
|
56
|
+
::DatabaseCleaner.connections.size.should eq 1
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should accept :moped" do
|
60
60
|
cleaner = ::DatabaseCleaner[:moped]
|
61
61
|
cleaner.should be_a(::DatabaseCleaner::Base)
|
62
|
-
cleaner.orm.should
|
63
|
-
::DatabaseCleaner.connections.size.should
|
62
|
+
cleaner.orm.should eq :moped
|
63
|
+
::DatabaseCleaner.connections.size.should eq 1
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'accepts :ohm' do
|
67
67
|
cleaner = ::DatabaseCleaner[:ohm]
|
68
68
|
cleaner.should be_a(::DatabaseCleaner::Base)
|
69
|
-
cleaner.orm.should
|
70
|
-
::DatabaseCleaner.connections.size.should
|
69
|
+
cleaner.orm.should eq :ohm
|
70
|
+
::DatabaseCleaner.connections.size.should eq 1
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should accept multiple orm's" do
|
75
75
|
::DatabaseCleaner[:couch_potato]
|
76
76
|
::DatabaseCleaner[:data_mapper]
|
77
|
-
::DatabaseCleaner.connections.size.should
|
78
|
-
::DatabaseCleaner.connections[0].orm.should
|
79
|
-
::DatabaseCleaner.connections[1].orm.should
|
77
|
+
::DatabaseCleaner.connections.size.should eq 2
|
78
|
+
::DatabaseCleaner.connections[0].orm.should eq :couch_potato
|
79
|
+
::DatabaseCleaner.connections[1].orm.should eq :data_mapper
|
80
80
|
end
|
81
81
|
|
82
82
|
context "connection/db specification" do
|
83
83
|
it "should accept a connection parameter and store it" do
|
84
84
|
cleaner = ::DatabaseCleaner[:active_record, {:connection => :first_connection}]
|
85
85
|
cleaner.should be_a(::DatabaseCleaner::Base)
|
86
|
-
cleaner.orm.should
|
87
|
-
cleaner.db.should
|
86
|
+
cleaner.orm.should eq :active_record
|
87
|
+
cleaner.db.should eq :first_connection
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should accept multiple connections for a single orm" do
|
91
91
|
::DatabaseCleaner[:data_mapper,{:connection => :first_db}]
|
92
92
|
::DatabaseCleaner[:data_mapper,{:connection => :second_db}]
|
93
|
-
::DatabaseCleaner.connections.size.should
|
94
|
-
::DatabaseCleaner.connections[0].orm.should
|
95
|
-
::DatabaseCleaner.connections[0].db.should
|
96
|
-
::DatabaseCleaner.connections[1].orm.should
|
97
|
-
::DatabaseCleaner.connections[1].db.should
|
93
|
+
::DatabaseCleaner.connections.size.should eq 2
|
94
|
+
::DatabaseCleaner.connections[0].orm.should eq :data_mapper
|
95
|
+
::DatabaseCleaner.connections[0].db.should eq :first_db
|
96
|
+
::DatabaseCleaner.connections[1].orm.should eq :data_mapper
|
97
|
+
::DatabaseCleaner.connections[1].db.should eq :second_db
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should accept multiple connections and multiple orms" do
|
@@ -103,19 +103,19 @@ describe ::DatabaseCleaner do
|
|
103
103
|
::DatabaseCleaner[:active_record,{:connection => :first_db} ]
|
104
104
|
::DatabaseCleaner[:data_mapper, {:connection => :second_db}]
|
105
105
|
|
106
|
-
::DatabaseCleaner.connections.size.should
|
106
|
+
::DatabaseCleaner.connections.size.should eq 4
|
107
107
|
|
108
|
-
::DatabaseCleaner.connections[0].orm.should
|
109
|
-
::DatabaseCleaner.connections[0].db.should
|
108
|
+
::DatabaseCleaner.connections[0].orm.should eq :data_mapper
|
109
|
+
::DatabaseCleaner.connections[0].db.should eq :first_db
|
110
110
|
|
111
|
-
::DatabaseCleaner.connections[1].orm.should
|
112
|
-
::DatabaseCleaner.connections[1].db.should
|
111
|
+
::DatabaseCleaner.connections[1].orm.should eq :active_record
|
112
|
+
::DatabaseCleaner.connections[1].db.should eq :second_db
|
113
113
|
|
114
|
-
::DatabaseCleaner.connections[2].orm.should
|
115
|
-
::DatabaseCleaner.connections[2].db.should
|
114
|
+
::DatabaseCleaner.connections[2].orm.should eq :active_record
|
115
|
+
::DatabaseCleaner.connections[2].db.should eq :first_db
|
116
116
|
|
117
|
-
::DatabaseCleaner.connections[3].orm.should
|
118
|
-
::DatabaseCleaner.connections[3].db.should
|
117
|
+
::DatabaseCleaner.connections[3].orm.should eq :data_mapper
|
118
|
+
::DatabaseCleaner.connections[3].db.should eq :second_db
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -123,7 +123,7 @@ describe ::DatabaseCleaner do
|
|
123
123
|
it "should retrieve a db rather than create a new one" do
|
124
124
|
pending
|
125
125
|
connection = ::DatabaseCleaner[:active_record].strategy = :truncation
|
126
|
-
::DatabaseCleaner[:active_record].should
|
126
|
+
::DatabaseCleaner[:active_record].should eq connection
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -131,10 +131,10 @@ describe ::DatabaseCleaner do
|
|
131
131
|
subject { ::DatabaseCleaner }
|
132
132
|
|
133
133
|
it "should give me a default (autodetection) databasecleaner by default" do
|
134
|
-
cleaner =
|
135
|
-
::DatabaseCleaner::Base.stub
|
134
|
+
cleaner = double("cleaner").as_null_object
|
135
|
+
::DatabaseCleaner::Base.stub(:new).and_return(cleaner)
|
136
136
|
|
137
|
-
::DatabaseCleaner.connections.should
|
137
|
+
::DatabaseCleaner.connections.should eq [cleaner]
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
@@ -142,13 +142,13 @@ describe ::DatabaseCleaner do
|
|
142
142
|
let(:connection) { ::DatabaseCleaner.connections.first }
|
143
143
|
|
144
144
|
it "should proxy strategy=" do
|
145
|
-
stratagum =
|
145
|
+
stratagum = double("stratagum")
|
146
146
|
connection.should_receive(:strategy=).with(stratagum)
|
147
147
|
::DatabaseCleaner.strategy = stratagum
|
148
148
|
end
|
149
149
|
|
150
150
|
it "should proxy orm=" do
|
151
|
-
orm =
|
151
|
+
orm = double("orm")
|
152
152
|
connection.should_receive(:orm=).with(orm)
|
153
153
|
::DatabaseCleaner.orm = orm
|
154
154
|
end
|
@@ -164,7 +164,7 @@ describe ::DatabaseCleaner do
|
|
164
164
|
end
|
165
165
|
|
166
166
|
it "should proxy clean_with" do
|
167
|
-
stratagem =
|
167
|
+
stratagem = double("stratgem")
|
168
168
|
connection.should_receive(:clean_with).with(stratagem, {})
|
169
169
|
::DatabaseCleaner.clean_with stratagem, {}
|
170
170
|
end
|
@@ -175,18 +175,18 @@ describe ::DatabaseCleaner do
|
|
175
175
|
#these are relativly simple, all we need to do is make sure all connections are cleaned/started/cleaned_with appropriatly.
|
176
176
|
context "simple proxy methods" do
|
177
177
|
|
178
|
-
let(:active_record) {
|
179
|
-
let(:data_mapper) {
|
178
|
+
let(:active_record) { double("active_mock") }
|
179
|
+
let(:data_mapper) { double("data_mock") }
|
180
180
|
|
181
181
|
before(:each) do
|
182
|
-
::DatabaseCleaner.stub
|
182
|
+
::DatabaseCleaner.stub(:connections).and_return([active_record,data_mapper])
|
183
183
|
end
|
184
184
|
|
185
185
|
it "should proxy orm to all connections" do
|
186
186
|
active_record.should_receive(:orm=)
|
187
187
|
data_mapper.should_receive(:orm=)
|
188
188
|
|
189
|
-
::DatabaseCleaner.orm =
|
189
|
+
::DatabaseCleaner.orm = double("orm")
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should proxy start to all connections" do
|
@@ -204,7 +204,7 @@ describe ::DatabaseCleaner do
|
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should proxy clean_with to all connections" do
|
207
|
-
stratagem =
|
207
|
+
stratagem = double("stratgem")
|
208
208
|
active_record.should_receive(:clean_with).with(stratagem)
|
209
209
|
data_mapper.should_receive(:clean_with).with(stratagem)
|
210
210
|
|
@@ -217,11 +217,11 @@ describe ::DatabaseCleaner do
|
|
217
217
|
context "multiple orm proxy methods" do
|
218
218
|
|
219
219
|
pending "should proxy orm to all connections and remove duplicate connections" do
|
220
|
-
active_record_1 =
|
221
|
-
active_record_2 =
|
222
|
-
data_mapper_1 =
|
220
|
+
active_record_1 = double("active_mock_on_db_one").as_null_object
|
221
|
+
active_record_2 = double("active_mock_on_db_two").as_null_object
|
222
|
+
data_mapper_1 = double("data_mock_on_db_one").as_null_object
|
223
223
|
|
224
|
-
::DatabaseCleaner.connections_stub
|
224
|
+
::DatabaseCleaner.connections_stub [active_record_1,active_record_2,data_mapper_1]
|
225
225
|
|
226
226
|
active_record_1.should_receive(:orm=).with(:data_mapper)
|
227
227
|
active_record_2.should_receive(:orm=).with(:data_mapper)
|
@@ -229,50 +229,50 @@ describe ::DatabaseCleaner do
|
|
229
229
|
|
230
230
|
active_record_1.should_receive(:==).with(data_mapper_1).and_return(true)
|
231
231
|
|
232
|
-
::DatabaseCleaner.connections.size.should
|
232
|
+
::DatabaseCleaner.connections.size.should eq 3
|
233
233
|
::DatabaseCleaner.orm = :data_mapper
|
234
|
-
::DatabaseCleaner.connections.size.should
|
234
|
+
::DatabaseCleaner.connections.size.should eq 2
|
235
235
|
end
|
236
236
|
|
237
237
|
it "should proxy strategy to all connections and remove duplicate connections" do
|
238
|
-
active_record_1 =
|
239
|
-
active_record_2 =
|
240
|
-
strategy =
|
238
|
+
active_record_1 = double("active_mock_strategy_one").as_null_object
|
239
|
+
active_record_2 = double("active_mock_strategy_two").as_null_object
|
240
|
+
strategy = double("strategy")
|
241
241
|
|
242
|
-
::DatabaseCleaner.connections_stub
|
242
|
+
::DatabaseCleaner.connections_stub [active_record_1,active_record_2]
|
243
243
|
|
244
244
|
active_record_1.should_receive(:strategy=).with(strategy)
|
245
245
|
active_record_2.should_receive(:strategy=).with(strategy)
|
246
246
|
|
247
247
|
active_record_1.should_receive(:==).with(active_record_2).and_return(true)
|
248
248
|
|
249
|
-
::DatabaseCleaner.connections.size.should
|
249
|
+
::DatabaseCleaner.connections.size.should eq 2
|
250
250
|
::DatabaseCleaner.strategy = strategy
|
251
|
-
::DatabaseCleaner.connections.size.should
|
251
|
+
::DatabaseCleaner.connections.size.should eq 1
|
252
252
|
end
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
256
256
|
describe "remove_duplicates" do
|
257
257
|
it "should remove duplicates if they are identical" do
|
258
|
-
orm =
|
259
|
-
connection =
|
258
|
+
orm = double("orm")
|
259
|
+
connection = double("a datamapper connection", :orm => orm )
|
260
260
|
|
261
|
-
::DatabaseCleaner.connections_stub
|
261
|
+
::DatabaseCleaner.connections_stub [connection,connection,connection]
|
262
262
|
|
263
263
|
::DatabaseCleaner.remove_duplicates
|
264
|
-
::DatabaseCleaner.connections.size.should
|
264
|
+
::DatabaseCleaner.connections.size.should eq 1
|
265
265
|
end
|
266
266
|
end
|
267
267
|
|
268
268
|
describe "app_root" do
|
269
269
|
it "should default to Dir.pwd" do
|
270
|
-
DatabaseCleaner.app_root.should
|
270
|
+
DatabaseCleaner.app_root.should eq Dir.pwd
|
271
271
|
end
|
272
272
|
|
273
273
|
it "should store specific paths" do
|
274
274
|
DatabaseCleaner.app_root = '/path/to'
|
275
|
-
DatabaseCleaner.app_root.should
|
275
|
+
DatabaseCleaner.app_root.should eq '/path/to'
|
276
276
|
end
|
277
277
|
end
|
278
278
|
|
@@ -280,33 +280,33 @@ describe ::DatabaseCleaner do
|
|
280
280
|
subject { ::DatabaseCleaner }
|
281
281
|
|
282
282
|
it "should return DatabaseCleaner::ActiveRecord for :active_record" do
|
283
|
-
::DatabaseCleaner::ActiveRecord =
|
284
|
-
subject.orm_module(:active_record).should
|
283
|
+
::DatabaseCleaner::ActiveRecord = double("ar module") unless defined? ::DatabaseCleaner::ActiveRecord
|
284
|
+
subject.orm_module(:active_record).should eq DatabaseCleaner::ActiveRecord
|
285
285
|
end
|
286
286
|
|
287
287
|
it "should return DatabaseCleaner::DataMapper for :data_mapper" do
|
288
|
-
::DatabaseCleaner::DataMapper =
|
289
|
-
subject.orm_module(:data_mapper).should
|
288
|
+
::DatabaseCleaner::DataMapper = double("dm module") unless defined? ::DatabaseCleaner::DataMapper
|
289
|
+
subject.orm_module(:data_mapper).should eq DatabaseCleaner::DataMapper
|
290
290
|
end
|
291
291
|
|
292
292
|
it "should return DatabaseCleaner::MongoMapper for :mongo_mapper" do
|
293
|
-
::DatabaseCleaner::MongoMapper =
|
294
|
-
subject.orm_module(:mongo_mapper).should
|
293
|
+
::DatabaseCleaner::MongoMapper = double("mm module") unless defined? ::DatabaseCleaner::MongoMapper
|
294
|
+
subject.orm_module(:mongo_mapper).should eq DatabaseCleaner::MongoMapper
|
295
295
|
end
|
296
296
|
|
297
297
|
it "should return DatabaseCleaner::Mongoid for :mongoid" do
|
298
|
-
::DatabaseCleaner::Mongoid =
|
299
|
-
subject.orm_module(:mongoid).should
|
298
|
+
::DatabaseCleaner::Mongoid = double("mongoid module") unless defined? ::DatabaseCleaner::Mongoid
|
299
|
+
subject.orm_module(:mongoid).should eq DatabaseCleaner::Mongoid
|
300
300
|
end
|
301
301
|
|
302
302
|
it "should return DatabaseCleaner::Mongo for :mongo" do
|
303
|
-
::DatabaseCleaner::Mongo =
|
304
|
-
subject.orm_module(:mongo).should
|
303
|
+
::DatabaseCleaner::Mongo = double("mongo module") unless defined? ::DatabaseCleaner::Mongo
|
304
|
+
subject.orm_module(:mongo).should eq DatabaseCleaner::Mongo
|
305
305
|
end
|
306
306
|
|
307
307
|
it "should return DatabaseCleaner::CouchPotato for :couch_potato" do
|
308
|
-
::DatabaseCleaner::CouchPotato =
|
309
|
-
subject.orm_module(:couch_potato).should
|
308
|
+
::DatabaseCleaner::CouchPotato = double("cp module") unless defined? ::DatabaseCleaner::CouchPotato
|
309
|
+
subject.orm_module(:couch_potato).should eq DatabaseCleaner::CouchPotato
|
310
310
|
end
|
311
311
|
|
312
312
|
end
|