database_cleaner 0.6.7 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/database_cleaner.rb +1 -3
- metadata +48 -154
- data/Gemfile.lock +0 -161
- data/History.txt +0 -173
- data/LICENSE +0 -20
- data/README.textile +0 -165
- data/Rakefile +0 -65
- data/TODO +0 -3
- data/VERSION.yml +0 -5
- data/cucumber.yml +0 -1
- data/examples/Gemfile +0 -48
- data/examples/Gemfile.lock +0 -161
- data/examples/config/database.yml.example +0 -8
- data/examples/db/sqlite_databases_go_here +0 -0
- data/examples/features/example.feature +0 -11
- data/examples/features/example_multiple_db.feature +0 -23
- data/examples/features/example_multiple_orm.feature +0 -22
- data/examples/features/step_definitions/activerecord_steps.rb +0 -31
- data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
- data/examples/features/step_definitions/datamapper_steps.rb +0 -37
- data/examples/features/step_definitions/mongoid_steps.rb +0 -23
- data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
- data/examples/features/step_definitions/translation_steps.rb +0 -55
- data/examples/features/support/env.rb +0 -62
- data/examples/lib/activerecord_models.rb +0 -41
- data/examples/lib/couchpotato_models.rb +0 -61
- data/examples/lib/datamapper_models.rb +0 -50
- data/examples/lib/mongoid_models.rb +0 -49
- data/examples/lib/mongomapper_models.rb +0 -51
- data/features/cleaning.feature +0 -22
- data/features/cleaning_default_strategy.feature +0 -19
- data/features/cleaning_multiple_dbs.feature +0 -21
- data/features/cleaning_multiple_orms.feature +0 -29
- data/features/step_definitions/database_cleaner_steps.rb +0 -32
- data/features/support/env.rb +0 -7
- data/features/support/feature_runner.rb +0 -39
- data/lib/database_cleaner/active_record/#transaction.rb# +0 -34
- data/lib/database_cleaner/active_record/base.rb +0 -53
- data/lib/database_cleaner/active_record/deletion.rb +0 -64
- data/lib/database_cleaner/active_record/transaction.rb +0 -26
- data/lib/database_cleaner/active_record/truncation.rb +0 -134
- data/lib/database_cleaner/base.rb +0 -136
- data/lib/database_cleaner/configuration.rb +0 -92
- data/lib/database_cleaner/couch_potato/base.rb +0 -7
- data/lib/database_cleaner/couch_potato/truncation.rb +0 -28
- data/lib/database_cleaner/cucumber.rb +0 -11
- data/lib/database_cleaner/data_mapper/base.rb +0 -21
- data/lib/database_cleaner/data_mapper/transaction.rb +0 -28
- data/lib/database_cleaner/data_mapper/truncation.rb +0 -175
- data/lib/database_cleaner/generic/base.rb +0 -23
- data/lib/database_cleaner/generic/truncation.rb +0 -43
- data/lib/database_cleaner/mongo/truncation.rb +0 -22
- data/lib/database_cleaner/mongo_mapper/base.rb +0 -20
- data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
- data/lib/database_cleaner/mongoid/base.rb +0 -20
- data/lib/database_cleaner/mongoid/truncation.rb +0 -20
- data/lib/database_cleaner/null_strategy.rb +0 -15
- data/spec/database_cleaner/active_record/base_spec.rb +0 -141
- data/spec/database_cleaner/active_record/transaction_spec.rb +0 -65
- data/spec/database_cleaner/active_record/truncation_spec.rb +0 -82
- data/spec/database_cleaner/base_spec.rb +0 -478
- data/spec/database_cleaner/configuration_spec.rb +0 -294
- data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
- data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
- data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
- data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
- data/spec/database_cleaner/generic/base_spec.rb +0 -22
- data/spec/database_cleaner/generic/truncation_spec.rb +0 -78
- data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
- data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
- data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
- data/spec/database_cleaner/shared_strategy_spec.rb +0 -13
- data/spec/rcov.opts +0 -1
- data/spec/spec.opts +0 -7
- data/spec/spec_helper.rb +0 -19
@@ -1,478 +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
|
-
|
8
|
-
module DatabaseCleaner
|
9
|
-
describe Base do
|
10
|
-
|
11
|
-
describe "autodetect" do
|
12
|
-
|
13
|
-
#Cache all ORMs, we'll need them later but not now.
|
14
|
-
before(:all) do
|
15
|
-
Temp_AR = ::ActiveRecord if defined?(::ActiveRecord) and not defined?(Temp_AR)
|
16
|
-
Temp_DM = ::DataMapper if defined?(::DataMapper) and not defined?(Temp_DM)
|
17
|
-
Temp_MM = ::MongoMapper if defined?(::MongoMapper) and not defined?(Temp_MM)
|
18
|
-
Temp_MO = ::Mongoid if defined?(::Mongoid) and not defined?(Temp_MO)
|
19
|
-
Temp_CP = ::CouchPotato if defined?(::CouchPotato) and not defined?(Temp_CP)
|
20
|
-
end
|
21
|
-
|
22
|
-
#Remove all ORM mocks and restore from cache
|
23
|
-
after(:all) do
|
24
|
-
Object.send(:remove_const, 'ActiveRecord') if defined?(::ActiveRecord)
|
25
|
-
Object.send(:remove_const, 'DataMapper') if defined?(::DataMapper)
|
26
|
-
Object.send(:remove_const, 'MongoMapper') if defined?(::MongoMapper)
|
27
|
-
Object.send(:remove_const, 'Mongoid') if defined?(::Mongoid)
|
28
|
-
Object.send(:remove_const, 'CouchPotato') if defined?(::CouchPotato)
|
29
|
-
|
30
|
-
|
31
|
-
# Restore ORMs
|
32
|
-
::ActiveRecord = Temp_AR if defined? Temp_AR
|
33
|
-
::DataMapper = Temp_DM if defined? Temp_DM
|
34
|
-
::MongoMapper = Temp_MM if defined? Temp_MM
|
35
|
-
::Mongoid = Temp_MO if defined? Temp_MO
|
36
|
-
::CouchPotato = Temp_CP if defined? Temp_CP
|
37
|
-
end
|
38
|
-
|
39
|
-
#reset the orm mocks
|
40
|
-
before(:each) do
|
41
|
-
Object.send(:remove_const, 'ActiveRecord') if defined?(::ActiveRecord)
|
42
|
-
Object.send(:remove_const, 'DataMapper') if defined?(::DataMapper)
|
43
|
-
Object.send(:remove_const, 'MongoMapper') if defined?(::MongoMapper)
|
44
|
-
Object.send(:remove_const, 'Mongoid') if defined?(::Mongoid)
|
45
|
-
Object.send(:remove_const, 'CouchPotato') if defined?(::CouchPotato)
|
46
|
-
end
|
47
|
-
|
48
|
-
let(:cleaner) { DatabaseCleaner::Base.new :autodetect }
|
49
|
-
|
50
|
-
it "should raise an error when no ORM is detected" do
|
51
|
-
running { cleaner }.should raise_error(DatabaseCleaner::NoORMDetected)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should detect ActiveRecord first" do
|
55
|
-
Object.const_set('ActiveRecord','Actively mocking records.')
|
56
|
-
Object.const_set('DataMapper', 'Mapping data mocks')
|
57
|
-
Object.const_set('MongoMapper', 'Mapping mock mongos')
|
58
|
-
Object.const_set('Mongoid', 'Mongoid mock')
|
59
|
-
Object.const_set('CouchPotato', 'Couching mock potatos')
|
60
|
-
|
61
|
-
cleaner.orm.should == :active_record
|
62
|
-
cleaner.should be_auto_detected
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should detect DataMapper second" do
|
66
|
-
Object.const_set('DataMapper', 'Mapping data mocks')
|
67
|
-
Object.const_set('MongoMapper', 'Mapping mock mongos')
|
68
|
-
Object.const_set('Mongoid', 'Mongoid mock')
|
69
|
-
Object.const_set('CouchPotato', 'Couching mock potatos')
|
70
|
-
|
71
|
-
cleaner.orm.should == :data_mapper
|
72
|
-
cleaner.should be_auto_detected
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should detect MongoMapper third" do
|
76
|
-
Object.const_set('MongoMapper', 'Mapping mock mongos')
|
77
|
-
Object.const_set('Mongoid', 'Mongoid mock')
|
78
|
-
Object.const_set('CouchPotato', 'Couching mock potatos')
|
79
|
-
|
80
|
-
cleaner.orm.should == :mongo_mapper
|
81
|
-
cleaner.should be_auto_detected
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should detect Mongoid fourth" do
|
85
|
-
Object.const_set('Mongoid', 'Mongoid mock')
|
86
|
-
Object.const_set('CouchPotato', 'Couching mock potatos')
|
87
|
-
|
88
|
-
cleaner.orm.should == :mongoid
|
89
|
-
cleaner.should be_auto_detected
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should detect CouchPotato last" do
|
93
|
-
Object.const_set('CouchPotato', 'Couching mock potatos')
|
94
|
-
|
95
|
-
cleaner.orm.should == :couch_potato
|
96
|
-
cleaner.should be_auto_detected
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "orm_module" do
|
101
|
-
it "should ask ::DatabaseCleaner what the module is for its orm" do
|
102
|
-
orm = mock("orm")
|
103
|
-
mockule = mock("module")
|
104
|
-
|
105
|
-
cleaner = ::DatabaseCleaner::Base.new
|
106
|
-
cleaner.should_receive(:orm).and_return(orm)
|
107
|
-
|
108
|
-
::DatabaseCleaner.should_receive(:orm_module).with(orm).and_return(mockule)
|
109
|
-
|
110
|
-
cleaner.send(:orm_module).should == mockule
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe "comparison" do
|
115
|
-
it "should be equal if orm, connection and strategy are the same" do
|
116
|
-
strategy = mock("strategy")
|
117
|
-
|
118
|
-
one = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
119
|
-
one.strategy = strategy
|
120
|
-
|
121
|
-
two = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
122
|
-
two.strategy = strategy
|
123
|
-
|
124
|
-
one.should == two
|
125
|
-
two.should == one
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "initialization" do
|
130
|
-
context "db specified" do
|
131
|
-
subject { ::DatabaseCleaner::Base.new(:active_record,:connection => :my_db) }
|
132
|
-
|
133
|
-
it "should store db from :connection in params hash" do
|
134
|
-
subject.db.should == :my_db
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe "orm" do
|
139
|
-
it "should store orm" do
|
140
|
-
cleaner = ::DatabaseCleaner::Base.new :a_orm
|
141
|
-
cleaner.orm.should == :a_orm
|
142
|
-
end
|
143
|
-
|
144
|
-
it "converts string to symbols" do
|
145
|
-
cleaner = ::DatabaseCleaner::Base.new "mongoid"
|
146
|
-
cleaner.orm.should == :mongoid
|
147
|
-
end
|
148
|
-
|
149
|
-
it "is autodetected if orm is not provided" do
|
150
|
-
cleaner = ::DatabaseCleaner::Base.new
|
151
|
-
cleaner.should be_auto_detected
|
152
|
-
end
|
153
|
-
|
154
|
-
it "is autodetected if you specify :autodetect" do
|
155
|
-
cleaner = ::DatabaseCleaner::Base.new "autodetect"
|
156
|
-
cleaner.should be_auto_detected
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should default to autodetect upon initalisation" do
|
160
|
-
subject.should be_auto_detected
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe "db" do
|
166
|
-
it "should default to :default" do
|
167
|
-
subject.db.should == :default
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should return any stored db value" do
|
171
|
-
subject.stub(:strategy_db=)
|
172
|
-
subject.db = :test_db
|
173
|
-
subject.db.should == :test_db
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should pass db to any specified strategy" do
|
177
|
-
subject.should_receive(:strategy_db=).with(:a_new_db)
|
178
|
-
subject.db = :a_new_db
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "strategy_db=" do
|
183
|
-
let(:strategy) { mock("strategy") }
|
184
|
-
|
185
|
-
before(:each) do
|
186
|
-
subject.strategy = strategy
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should check that strategy supports db specification" do
|
190
|
-
strategy.should_receive(:respond_to?).with(:db=).and_return(true)
|
191
|
-
strategy.stub(:db=)
|
192
|
-
subject.strategy_db = :a_db
|
193
|
-
end
|
194
|
-
|
195
|
-
context "when strategy supports db specification" do
|
196
|
-
before(:each) { strategy.stub(:respond_to?).with(:db=).and_return true }
|
197
|
-
|
198
|
-
it "should pass db to the strategy" do
|
199
|
-
strategy.should_receive(:db=).with(:a_db)
|
200
|
-
subject.strategy_db = :a_db
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
context "when strategy doesn't supports db specification" do
|
205
|
-
before(:each) { strategy.stub(:respond_to?).with(:db=).and_return false }
|
206
|
-
|
207
|
-
it "should check to see if db is :default" do
|
208
|
-
db = mock("default")
|
209
|
-
db.should_receive(:==).with(:default).and_return(true)
|
210
|
-
|
211
|
-
subject.strategy_db = db
|
212
|
-
end
|
213
|
-
|
214
|
-
it "should raise an argument error when db isn't default" do
|
215
|
-
db = mock("a db")
|
216
|
-
expect{ subject.strategy_db = db }.to raise_error ArgumentError
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
describe "clean_with" do
|
222
|
-
let (:strategy) { mock("strategy",:clean => true) }
|
223
|
-
|
224
|
-
before(:each) { subject.stub(:create_strategy).with(anything).and_return(strategy) }
|
225
|
-
|
226
|
-
it "should pass all arguments to create_strategy" do
|
227
|
-
subject.should_receive(:create_strategy).with(:lorum, :dollar, :amet, :ipsum => "random").and_return(strategy)
|
228
|
-
subject.clean_with :lorum, :dollar, :amet, { :ipsum => "random" }
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should invoke clean on the created strategy" do
|
232
|
-
strategy.should_receive(:clean)
|
233
|
-
subject.clean_with :strategy
|
234
|
-
end
|
235
|
-
|
236
|
-
it "should return the strategy" do
|
237
|
-
subject.clean_with( :strategy ).should == strategy
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
describe "clean_with!" do
|
242
|
-
let (:strategy) { mock("strategy",:clean => true) }
|
243
|
-
|
244
|
-
before(:each) { subject.stub(:create_strategy).with(anything).and_return(strategy) }
|
245
|
-
|
246
|
-
it "should pass all arguments to create_strategy" do
|
247
|
-
subject.should_receive(:create_strategy).with(:lorum, :dollar, :amet, :ipsum => "random").and_return(strategy)
|
248
|
-
subject.clean_with! :lorum, :dollar, :amet, { :ipsum => "random" }
|
249
|
-
end
|
250
|
-
|
251
|
-
it "should invoke clean on the created strategy" do
|
252
|
-
strategy.should_receive(:clean)
|
253
|
-
subject.clean_with! :strategy
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should return the strategy" do
|
257
|
-
subject.clean_with!( :strategy ).should == strategy
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
describe "create_strategy" do
|
262
|
-
let(:klass) { mock("klass",:new => mock("instance")) }
|
263
|
-
|
264
|
-
before :each do
|
265
|
-
subject.stub(:orm_strategy).and_return(klass)
|
266
|
-
end
|
267
|
-
|
268
|
-
it "should pass the first argument to orm_strategy" do
|
269
|
-
subject.should_receive(:orm_strategy).with(:strategy).and_return(Object)
|
270
|
-
subject.create_strategy :strategy
|
271
|
-
end
|
272
|
-
it "should pass the remainding argument to orm_strategy.new" do
|
273
|
-
klass.should_receive(:new).with(:params => {:lorum => "ipsum"})
|
274
|
-
|
275
|
-
subject.create_strategy :strategy, {:params => {:lorum => "ipsum"}}
|
276
|
-
end
|
277
|
-
it "should return the resulting strategy" do
|
278
|
-
subject.create_strategy( :strategy ).should == klass.new
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
describe "strategy=" do
|
283
|
-
let(:mock_strategy) { mock("strategy") }
|
284
|
-
|
285
|
-
it "should proxy symbolised strategies to create_strategy" do
|
286
|
-
subject.should_receive(:create_strategy).with(:symbol)
|
287
|
-
subject.strategy = :symbol
|
288
|
-
end
|
289
|
-
|
290
|
-
it "should proxy params with symbolised strategies" do
|
291
|
-
subject.should_receive(:create_strategy).with(:symbol,:param => "one")
|
292
|
-
subject.strategy= :symbol, {:param => "one"}
|
293
|
-
end
|
294
|
-
|
295
|
-
it "should accept strategy objects" do
|
296
|
-
expect{ subject.strategy = mock_strategy }.to_not raise_error
|
297
|
-
end
|
298
|
-
|
299
|
-
it "should raise argument error when params given with strategy Object" do
|
300
|
-
expect{ subject.strategy = mock("object"), {:param => "one"} }.to raise_error ArgumentError
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should attempt to set strategy db" do
|
304
|
-
subject.stub(:db).and_return(:my_db)
|
305
|
-
subject.should_receive(:strategy_db=).with(:my_db)
|
306
|
-
subject.strategy = mock_strategy
|
307
|
-
end
|
308
|
-
|
309
|
-
it "should return the stored strategy" do
|
310
|
-
result = subject.strategy = mock_strategy
|
311
|
-
result.should == mock_strategy
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
describe "strategy" do
|
316
|
-
subject { ::DatabaseCleaner::Base.new :a_orm }
|
317
|
-
|
318
|
-
it "returns a null strategy when strategy no set and undetectable" do
|
319
|
-
subject.instance_values["@strategy"] = nil
|
320
|
-
subject.strategy.should == DatabaseCleaner::NullStrategy
|
321
|
-
end
|
322
|
-
|
323
|
-
it "returns the set strategy" do
|
324
|
-
strategum = mock("strategy")
|
325
|
-
subject.strategy = strategum
|
326
|
-
subject.strategy.should == strategum
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
describe "orm=" do
|
331
|
-
it "should stored the desired orm" do
|
332
|
-
subject.orm.should_not == :desired_orm
|
333
|
-
subject.orm = :desired_orm
|
334
|
-
subject.orm.should == :desired_orm
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
describe "orm" do
|
339
|
-
let(:mock_orm) { mock("orm") }
|
340
|
-
|
341
|
-
it "should return orm if orm set" do
|
342
|
-
subject.instance_variable_set "@orm", mock_orm
|
343
|
-
subject.orm.should == mock_orm
|
344
|
-
end
|
345
|
-
|
346
|
-
context "orm isn't set" do
|
347
|
-
before(:each) { subject.instance_variable_set "@orm", nil }
|
348
|
-
|
349
|
-
it "should run autodetect if orm isn't set" do
|
350
|
-
subject.should_receive(:autodetect)
|
351
|
-
subject.orm
|
352
|
-
end
|
353
|
-
|
354
|
-
it "should return the result of autodetect if orm isn't set" do
|
355
|
-
subject.stub(:autodetect).and_return(mock_orm)
|
356
|
-
subject.orm.should == mock_orm
|
357
|
-
end
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
describe "proxy methods" do
|
362
|
-
let (:strategy) { mock("strategy") }
|
363
|
-
|
364
|
-
before(:each) do
|
365
|
-
subject.stub(:strategy).and_return(strategy)
|
366
|
-
end
|
367
|
-
|
368
|
-
describe "start" do
|
369
|
-
it "should proxy start to the strategy" do
|
370
|
-
strategy.should_receive(:start)
|
371
|
-
subject.start
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
describe "clean" do
|
376
|
-
it "should proxy clean to the strategy" do
|
377
|
-
strategy.should_receive(:clean)
|
378
|
-
subject.clean
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
describe "clean!" do
|
383
|
-
it "should proxy clean! to the strategy clean" do
|
384
|
-
strategy.should_receive(:clean)
|
385
|
-
subject.clean!
|
386
|
-
end
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
describe "auto_detected?" do
|
391
|
-
it "should return true unless @autodetected is nil" do
|
392
|
-
subject.instance_variable_set("@autodetected","not nil")
|
393
|
-
subject.auto_detected?.should be_true
|
394
|
-
end
|
395
|
-
|
396
|
-
it "should return false if @autodetect is nil" do
|
397
|
-
subject.instance_variable_set("@autodetected",nil)
|
398
|
-
subject.auto_detected?.should be_false
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
describe "orm_strategy" do
|
403
|
-
let (:klass) { mock("klass") }
|
404
|
-
|
405
|
-
before(:each) do
|
406
|
-
subject.stub(:orm_module).and_return(klass)
|
407
|
-
end
|
408
|
-
|
409
|
-
context "in response to a LoadError" do
|
410
|
-
before(:each) { subject.should_receive(:require).with(anything).and_raise(LoadError) }
|
411
|
-
|
412
|
-
it "should catch LoadErrors" do
|
413
|
-
expect { subject.send(:orm_strategy,:a_strategy) }.to_not raise_error LoadError
|
414
|
-
end
|
415
|
-
|
416
|
-
it "should raise UnknownStrategySpecified" do
|
417
|
-
expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
|
418
|
-
end
|
419
|
-
|
420
|
-
it "should ask orm_module if it will list available_strategies" do
|
421
|
-
klass.should_receive(:respond_to?).with(:available_strategies)
|
422
|
-
|
423
|
-
subject.stub(:orm_module).and_return(klass)
|
424
|
-
|
425
|
-
expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
|
426
|
-
end
|
427
|
-
|
428
|
-
it "should use available_strategies (for the error message) if its available" do
|
429
|
-
klass.stub(:respond_to?).with(:available_strategies).and_return(true)
|
430
|
-
klass.should_receive(:available_strategies).and_return([])
|
431
|
-
|
432
|
-
subject.stub(:orm_module).and_return(klass)
|
433
|
-
|
434
|
-
expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
|
435
|
-
end
|
436
|
-
end
|
437
|
-
|
438
|
-
it "should return the constant of the Strategy class requested" do
|
439
|
-
strategy_klass = mock("strategy klass")
|
440
|
-
|
441
|
-
subject.stub(:require).with(anything).and_return(true)
|
442
|
-
|
443
|
-
klass.should_receive(:const_get).with("Cunningplan").and_return(strategy_klass)
|
444
|
-
|
445
|
-
subject.send(:orm_strategy, :cunningplan).should == strategy_klass
|
446
|
-
end
|
447
|
-
|
448
|
-
end
|
449
|
-
|
450
|
-
describe 'set_default_orm_strategy' do
|
451
|
-
it 'sets strategy to :transaction for ActiveRecord' do
|
452
|
-
cleaner = DatabaseCleaner::Base.new(:active_record)
|
453
|
-
cleaner.strategy.should be_instance_of DatabaseCleaner::ActiveRecord::Transaction
|
454
|
-
end
|
455
|
-
|
456
|
-
it 'sets strategy to :transaction for DataMapper' do
|
457
|
-
cleaner = DatabaseCleaner::Base.new(:data_mapper)
|
458
|
-
cleaner.strategy.should be_instance_of DatabaseCleaner::DataMapper::Transaction
|
459
|
-
end
|
460
|
-
|
461
|
-
it 'sets strategy to :truncation for MongoMapper' do
|
462
|
-
cleaner = DatabaseCleaner::Base.new(:mongo_mapper)
|
463
|
-
cleaner.strategy.should be_instance_of DatabaseCleaner::MongoMapper::Truncation
|
464
|
-
end
|
465
|
-
|
466
|
-
it 'sets strategy to :truncation for Mongoid' do
|
467
|
-
cleaner = DatabaseCleaner::Base.new(:mongoid)
|
468
|
-
cleaner.strategy.should be_instance_of DatabaseCleaner::Mongoid::Truncation
|
469
|
-
end
|
470
|
-
|
471
|
-
it 'sets strategy to :truncation for CouchPotato' do
|
472
|
-
cleaner = DatabaseCleaner::Base.new(:couch_potato)
|
473
|
-
cleaner.strategy.should be_instance_of DatabaseCleaner::CouchPotato::Truncation
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
end
|
478
|
-
end
|