database_cleaner 1.6.2 → 2.0.0

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 +18 -498
  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,345 +0,0 @@
1
- require 'spec_helper'
2
- module ArrayHelper
3
- def zipmap(array, vals)
4
- Hash[*(array.zip(vals).flatten)]
5
- end
6
- module_function :zipmap
7
- end
8
-
9
- module DatabaseCleaner
10
- class << self
11
- def reset
12
- @cleaners = nil
13
- @connections = nil
14
- end
15
- # hackey, hack.. connections needs to stick around until I can properly deprecate the API
16
- def connections_stub(array)
17
- @cleaners = ArrayHelper.zipmap((1..array.size).to_a, array)
18
- @connections = array
19
- end
20
- end
21
- end
22
-
23
- describe ::DatabaseCleaner do
24
- before(:each) { ::DatabaseCleaner.reset }
25
-
26
- context "orm specification" do
27
- it "should not accept unrecognised orms" do
28
- expect { ::DatabaseCleaner[nil] }.to raise_error(::DatabaseCleaner::NoORMDetected)
29
- end
30
-
31
- it "should accept :active_record" do
32
- cleaner = ::DatabaseCleaner[:active_record]
33
- cleaner.should be_a(::DatabaseCleaner::Base)
34
- cleaner.orm.should eq :active_record
35
- ::DatabaseCleaner.connections.size.should eq 1
36
- end
37
-
38
- it "should accept :data_mapper" do
39
- cleaner = ::DatabaseCleaner[:data_mapper]
40
- cleaner.should be_a(::DatabaseCleaner::Base)
41
- cleaner.orm.should eq :data_mapper
42
- ::DatabaseCleaner.connections.size.should eq 1
43
- end
44
-
45
- it "should accept :mongo_mapper" do
46
- cleaner = ::DatabaseCleaner[:mongo_mapper]
47
- cleaner.should be_a(::DatabaseCleaner::Base)
48
- cleaner.orm.should eq :mongo_mapper
49
- ::DatabaseCleaner.connections.size.should eq 1
50
- end
51
-
52
- it "should accept :couch_potato" do
53
- cleaner = ::DatabaseCleaner[:couch_potato]
54
- cleaner.should be_a(::DatabaseCleaner::Base)
55
- cleaner.orm.should eq :couch_potato
56
- ::DatabaseCleaner.connections.size.should eq 1
57
- end
58
-
59
- it "should accept :moped" do
60
- cleaner = ::DatabaseCleaner[:moped]
61
- cleaner.should be_a(::DatabaseCleaner::Base)
62
- cleaner.orm.should eq :moped
63
- ::DatabaseCleaner.connections.size.should eq 1
64
- end
65
-
66
- it 'accepts :ohm' do
67
- cleaner = ::DatabaseCleaner[:ohm]
68
- cleaner.should be_a(::DatabaseCleaner::Base)
69
- cleaner.orm.should eq :ohm
70
- ::DatabaseCleaner.connections.size.should eq 1
71
- end
72
- end
73
-
74
- it "should accept multiple orm's" do
75
- ::DatabaseCleaner[:couch_potato]
76
- ::DatabaseCleaner[:data_mapper]
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
- end
81
-
82
- context "connection/db specification" do
83
- it "should accept a connection parameter and store it" do
84
- cleaner = ::DatabaseCleaner[:active_record, {:connection => :first_connection}]
85
- cleaner.should be_a(::DatabaseCleaner::Base)
86
- cleaner.orm.should eq :active_record
87
- cleaner.db.should eq :first_connection
88
- end
89
-
90
- it "should accept multiple connections for a single orm" do
91
- ::DatabaseCleaner[:data_mapper,{:connection => :first_db}]
92
- ::DatabaseCleaner[:data_mapper,{:connection => :second_db}]
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
- end
99
-
100
- it "should accept multiple connections and multiple orms" do
101
- ::DatabaseCleaner[:data_mapper, {:connection => :first_db} ]
102
- ::DatabaseCleaner[:active_record,{:connection => :second_db}]
103
- ::DatabaseCleaner[:active_record,{:connection => :first_db} ]
104
- ::DatabaseCleaner[:data_mapper, {:connection => :second_db}]
105
-
106
- ::DatabaseCleaner.connections.size.should eq 4
107
-
108
- ::DatabaseCleaner.connections[0].orm.should eq :data_mapper
109
- ::DatabaseCleaner.connections[0].db.should eq :first_db
110
-
111
- ::DatabaseCleaner.connections[1].orm.should eq :active_record
112
- ::DatabaseCleaner.connections[1].db.should eq :second_db
113
-
114
- ::DatabaseCleaner.connections[2].orm.should eq :active_record
115
- ::DatabaseCleaner.connections[2].db.should eq :first_db
116
-
117
- ::DatabaseCleaner.connections[3].orm.should eq :data_mapper
118
- ::DatabaseCleaner.connections[3].db.should eq :second_db
119
- end
120
- end
121
-
122
- context "connection/db retrieval" do
123
- it "should retrieve a db rather than create a new one" do
124
- pending
125
- connection = ::DatabaseCleaner[:active_record].strategy = :truncation
126
- ::DatabaseCleaner[:active_record].should eq connection
127
- end
128
- end
129
-
130
- context "class methods" do
131
- subject { ::DatabaseCleaner }
132
-
133
- it "should give me a default (autodetection) databasecleaner by default" do
134
- cleaner = double("cleaner").as_null_object
135
- ::DatabaseCleaner::Base.stub(:new).and_return(cleaner)
136
-
137
- ::DatabaseCleaner.connections.should eq [cleaner]
138
- end
139
- end
140
-
141
- context "single orm single connection" do
142
- let(:connection) { ::DatabaseCleaner.connections.first }
143
-
144
- it "should proxy strategy=" do
145
- stratagum = double("stratagum")
146
- connection.should_receive(:strategy=).with(stratagum)
147
- ::DatabaseCleaner.strategy = stratagum
148
- end
149
-
150
- it "should proxy orm=" do
151
- orm = double("orm")
152
- connection.should_receive(:orm=).with(orm)
153
- ::DatabaseCleaner.orm = orm
154
- end
155
-
156
- it "should proxy start" do
157
- connection.should_receive(:start)
158
- ::DatabaseCleaner.start
159
- end
160
-
161
- it "should proxy clean" do
162
- connection.should_receive(:clean)
163
- ::DatabaseCleaner.clean
164
- end
165
-
166
- it 'should proxy cleaning' do
167
- connection.should_receive(:cleaning)
168
- ::DatabaseCleaner.cleaning { }
169
- end
170
-
171
- it "should proxy clean_with" do
172
- stratagem = double("stratgem")
173
- connection.should_receive(:clean_with).with(stratagem, {})
174
- ::DatabaseCleaner.clean_with stratagem, {}
175
- end
176
- end
177
-
178
- context "multiple connections" do
179
-
180
- #these are relativly simple, all we need to do is make sure all connections are cleaned/started/cleaned_with appropriatly.
181
- context "simple proxy methods" do
182
-
183
- let(:active_record) { double("active_mock") }
184
- let(:data_mapper) { double("data_mock") }
185
-
186
- before(:each) do
187
- ::DatabaseCleaner.stub(:connections).and_return([active_record,data_mapper])
188
- end
189
-
190
- it "should proxy orm to all connections" do
191
- active_record.should_receive(:orm=)
192
- data_mapper.should_receive(:orm=)
193
-
194
- ::DatabaseCleaner.orm = double("orm")
195
- end
196
-
197
- it "should proxy start to all connections" do
198
- active_record.should_receive(:start)
199
- data_mapper.should_receive(:start)
200
-
201
- ::DatabaseCleaner.start
202
- end
203
-
204
- it "should proxy clean to all connections" do
205
- active_record.should_receive(:clean)
206
- data_mapper.should_receive(:clean)
207
-
208
- ::DatabaseCleaner.clean
209
- end
210
-
211
- it "should initiate cleaning on each connection, yield, and finish cleaning each connection" do
212
- [active_record, data_mapper].each do |connection|
213
- mc = class << connection; self; end
214
- mc.send(:attr_reader, :started, :cleaned)
215
- mc.send(:define_method, 'cleaning') do |&block|
216
- @started = true
217
- block.call
218
- @cleaned = true
219
- end
220
- end
221
-
222
- ::DatabaseCleaner.cleaning do
223
- active_record.started.should == true
224
- data_mapper.started.should == true
225
- active_record.cleaned.should == nil
226
- data_mapper.cleaned.should == nil
227
- @yielded = true
228
- end
229
- active_record.cleaned.should == true
230
- data_mapper.cleaned.should == true
231
- end
232
-
233
- it "should proxy clean_with to all connections" do
234
- stratagem = double("stratgem")
235
- active_record.should_receive(:clean_with).with(stratagem)
236
- data_mapper.should_receive(:clean_with).with(stratagem)
237
-
238
- ::DatabaseCleaner.clean_with stratagem
239
- end
240
- end
241
-
242
- # ah now we have some difficulty, we mustn't allow duplicate connections to exist, but they could
243
- # plausably want to force orm/strategy change on two sets of orm that differ only on db
244
- context "multiple orm proxy methods" do
245
-
246
- pending "should proxy orm to all connections and remove duplicate connections" do
247
- active_record_1 = double("active_mock_on_db_one").as_null_object
248
- active_record_2 = double("active_mock_on_db_two").as_null_object
249
- data_mapper_1 = double("data_mock_on_db_one").as_null_object
250
-
251
- ::DatabaseCleaner.connections_stub [active_record_1,active_record_2,data_mapper_1]
252
-
253
- active_record_1.should_receive(:orm=).with(:data_mapper)
254
- active_record_2.should_receive(:orm=).with(:data_mapper)
255
- data_mapper_1.should_receive(:orm=).with(:data_mapper)
256
-
257
- active_record_1.should_receive(:==).with(data_mapper_1).and_return(true)
258
-
259
- ::DatabaseCleaner.connections.size.should eq 3
260
- ::DatabaseCleaner.orm = :data_mapper
261
- ::DatabaseCleaner.connections.size.should eq 2
262
- end
263
-
264
- it "should proxy strategy to all connections and remove duplicate connections" do
265
- active_record_1 = double("active_mock_strategy_one").as_null_object
266
- active_record_2 = double("active_mock_strategy_two").as_null_object
267
- strategy = double("strategy")
268
-
269
- ::DatabaseCleaner.connections_stub [active_record_1,active_record_2]
270
-
271
- active_record_1.should_receive(:strategy=).with(strategy)
272
- active_record_2.should_receive(:strategy=).with(strategy)
273
-
274
- active_record_1.should_receive(:==).with(active_record_2).and_return(true)
275
-
276
- ::DatabaseCleaner.connections.size.should eq 2
277
- ::DatabaseCleaner.strategy = strategy
278
- ::DatabaseCleaner.connections.size.should eq 1
279
- end
280
- end
281
- end
282
-
283
- describe "remove_duplicates" do
284
- it "should remove duplicates if they are identical" do
285
- orm = double("orm")
286
- connection = double("a datamapper connection", :orm => orm )
287
-
288
- ::DatabaseCleaner.connections_stub [connection,connection,connection]
289
-
290
- ::DatabaseCleaner.remove_duplicates
291
- ::DatabaseCleaner.connections.size.should eq 1
292
- end
293
- end
294
-
295
- describe "app_root" do
296
- it "should default to Dir.pwd" do
297
- DatabaseCleaner.app_root.should eq Dir.pwd
298
- end
299
-
300
- it "should store specific paths" do
301
- DatabaseCleaner.app_root = '/path/to'
302
- DatabaseCleaner.app_root.should eq '/path/to'
303
- end
304
- end
305
-
306
- describe "orm_module" do
307
- subject { ::DatabaseCleaner }
308
-
309
- it "should return DatabaseCleaner::ActiveRecord for :active_record" do
310
- ::DatabaseCleaner::ActiveRecord = double("ar module") unless defined? ::DatabaseCleaner::ActiveRecord
311
- subject.orm_module(:active_record).should eq DatabaseCleaner::ActiveRecord
312
- end
313
-
314
- it "should return DatabaseCleaner::DataMapper for :data_mapper" do
315
- ::DatabaseCleaner::DataMapper = double("dm module") unless defined? ::DatabaseCleaner::DataMapper
316
- subject.orm_module(:data_mapper).should eq DatabaseCleaner::DataMapper
317
- end
318
-
319
- it "should return DatabaseCleaner::MongoMapper for :mongo_mapper" do
320
- ::DatabaseCleaner::MongoMapper = double("mm module") unless defined? ::DatabaseCleaner::MongoMapper
321
- subject.orm_module(:mongo_mapper).should eq DatabaseCleaner::MongoMapper
322
- end
323
-
324
- it "should return DatabaseCleaner::Mongoid for :mongoid" do
325
- ::DatabaseCleaner::Mongoid = double("mongoid module") unless defined? ::DatabaseCleaner::Mongoid
326
- subject.orm_module(:mongoid).should eq DatabaseCleaner::Mongoid
327
- end
328
-
329
- it "should return DatabaseCleaner::Mongo for :mongo" do
330
- ::DatabaseCleaner::Mongo = double("mongo module") unless defined? ::DatabaseCleaner::Mongo
331
- subject.orm_module(:mongo).should eq DatabaseCleaner::Mongo
332
- end
333
-
334
- it "should return DatabaseCleaner::CouchPotato for :couch_potato" do
335
- ::DatabaseCleaner::CouchPotato = double("cp module") unless defined? ::DatabaseCleaner::CouchPotato
336
- subject.orm_module(:couch_potato).should eq DatabaseCleaner::CouchPotato
337
- end
338
-
339
- it "should return DatabaseCleaner::Neo4j for :neo4j" do
340
- ::DatabaseCleaner::Neo4j = double("nj module") unless defined? ::DatabaseCleaner::Neo4j
341
- subject.orm_module(:neo4j).should eq DatabaseCleaner::Neo4j
342
- end
343
-
344
- end
345
- end
@@ -1,41 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'database_cleaner/couch_potato/truncation'
3
- require 'couch_potato'
4
-
5
- module DatabaseCleaner
6
- module CouchPotato
7
-
8
- describe Truncation do
9
- let(:database) { double('database') }
10
-
11
- before(:each) do
12
- ::CouchPotato.stub(:couchrest_database).and_return(database)
13
- end
14
-
15
- it "should re-create the database" do
16
- database.should_receive(:recreate!)
17
-
18
- Truncation.new.clean
19
- end
20
-
21
- it "should raise an error when the :only option is used" do
22
- running {
23
- Truncation.new(:only => ['document-type'])
24
- }.should raise_error(ArgumentError)
25
- end
26
-
27
- it "should raise an error when the :except option is used" do
28
- running {
29
- Truncation.new(:except => ['document-type'])
30
- }.should raise_error(ArgumentError)
31
- end
32
-
33
- it "should raise an error when invalid options are provided" do
34
- running {
35
- Truncation.new(:foo => 'bar')
36
- }.should raise_error(ArgumentError)
37
- end
38
- end
39
-
40
- end
41
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/data_mapper/base'
3
- require 'database_cleaner/shared_strategy'
4
-
5
- module DatabaseCleaner
6
- describe DataMapper do
7
- it { should respond_to(:available_strategies) }
8
- end
9
-
10
- module DataMapper
11
- class ExampleStrategy
12
- include ::DatabaseCleaner::DataMapper::Base
13
- end
14
-
15
- describe ExampleStrategy do
16
- it_should_behave_like "a generic strategy"
17
- it { should respond_to(:db) }
18
- it { should respond_to(:db=) }
19
-
20
- it "should store my desired db" do
21
- subject.db = :my_db
22
- subject.db.should eq :my_db
23
- end
24
-
25
- it "should default to :default" do
26
- subject.db.should eq :default
27
- end
28
- end
29
- end
30
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'database_cleaner/data_mapper/transaction'
3
- require 'database_cleaner/shared_strategy'
4
- #require 'data_mapper'
5
-
6
- module DatabaseCleaner
7
- module DataMapper
8
-
9
- describe Transaction do
10
- it_should_behave_like "a generic strategy"
11
- it_should_behave_like "a generic transaction strategy"
12
-
13
- describe "start" do
14
- it "should start a transaction"
15
- end
16
-
17
- describe "clean" do
18
- it "should finish a transaction"
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
- require 'dm-core'
3
- require 'dm-sqlite-adapter'
4
- require File.expand_path('../../../../support/data_mapper/sqlite3_setup', __FILE__)
5
- require 'database_cleaner/data_mapper/truncation'
6
-
7
- module DataMapper
8
- module ConnectionAdapters
9
- describe do
10
- before(:all) { data_mapper_sqlite3_setup }
11
-
12
- let(:adapter) { DataMapperSQLite3Adapter }
13
-
14
- let(:connection) do
15
- data_mapper_sqlite3_connection
16
- end
17
-
18
- before(:each) do
19
- connection.truncate_tables(DataMapper::Model.descendants.map { |d| d.storage_names[:default] || d.name.underscore })
20
- end
21
-
22
- describe "#truncate_table" do
23
- it "truncates the table" do
24
- 2.times { DmUser.create }
25
-
26
- connection.truncate_table(DmUser.storage_names[:default])
27
- DmUser.count.should eq 0
28
- end
29
-
30
- it "resets AUTO_INCREMENT index of table" do
31
- 2.times { DmUser.create }
32
- DmUser.destroy
33
-
34
- connection.truncate_table(DmUser.storage_names[:default])
35
-
36
- DmUser.create.id.should eq 1
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,11 +0,0 @@
1
- require 'database_cleaner/data_mapper/truncation'
2
- require 'database_cleaner/shared_strategy'
3
-
4
- module DatabaseCleaner
5
- module DataMapper
6
- describe Truncation do
7
- it_should_behave_like "a generic strategy"
8
- it_should_behave_like "a generic truncation strategy"
9
- end
10
- end
11
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/shared_strategy'
3
- require 'database_cleaner/generic/base'
4
- require 'active_record'
5
-
6
- module ::DatabaseCleaner
7
- module Generic
8
- class ExampleStrategy
9
- include ::DatabaseCleaner::Generic::Base
10
-
11
- def start; end
12
- end
13
-
14
- describe ExampleStrategy do
15
- context "class methods" do
16
- subject { ExampleStrategy }
17
-
18
- describe "#available_strategies" do
19
- it "should have available strategies" do
20
- expect(subject.available_strategies).to be_empty
21
- end
22
- end
23
- end
24
-
25
- it_should_behave_like "a generic strategy"
26
-
27
- describe "#db" do
28
- it "should be :default" do
29
- expect(subject.db).to eql(:default)
30
- end
31
- end
32
-
33
- describe "#cleaning" do
34
- let (:connection) { double("connection") }
35
- let (:strategy) { ExampleStrategy.new }
36
- before do
37
- # DatabaseCleaner.strategy = :truncation
38
- connection.stub(:disable_referential_integrity).and_yield
39
- connection.stub(:database_cleaner_view_cache).and_return([])
40
- connection.stub(:database_cleaner_table_cache).and_return([])
41
- ::ActiveRecord::Base.stub(:connection).and_return(connection)
42
- end
43
-
44
- it "calls #clean even if there is an exception" do
45
- strategy.should_receive :clean
46
- expect do
47
- strategy.cleaning do
48
- raise NoMethodError
49
- end
50
- end.to raise_exception(NoMethodError)
51
- end
52
-
53
- it "calls #clean after processing the block" do
54
- strategy.should_receive :clean
55
- strategy.cleaning do
56
- end
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,118 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/generic/truncation'
3
-
4
- module ::DatabaseCleaner
5
- module Generic
6
- class TruncationExample
7
- include ::DatabaseCleaner::Generic::Truncation
8
-
9
- def only
10
- @only
11
- end
12
-
13
- def except
14
- @tables_to_exclude
15
- end
16
-
17
- def reset_ids?
18
- !!@reset_ids
19
- end
20
-
21
- def pre_count?
22
- !!@pre_count
23
- end
24
- end
25
-
26
- class MigrationExample < TruncationExample
27
- def migration_storage_names
28
- %w[migration_storage_name]
29
- end
30
- end
31
-
32
- describe TruncationExample do
33
- subject(:truncation_example) { TruncationExample.new }
34
-
35
- it "will start" do
36
- expect { truncation_example.start }.to_not raise_error
37
- end
38
-
39
- it "expects clean to be implemented later" do
40
- expect { truncation_example.clean }.to raise_error(NotImplementedError)
41
- end
42
-
43
- context "private methods" do
44
- it { should_not respond_to(:tables_to_truncate) }
45
-
46
- it 'expects #tables_to_truncate to be implemented later' do
47
- expect{ truncation_example.send :tables_to_truncate }.to raise_error(NotImplementedError)
48
- end
49
-
50
- it { should_not respond_to(:migration_storage_names) }
51
- its(:migration_storage_names) { should be_empty }
52
- end
53
-
54
- describe "initialize" do
55
- it { expect{ subject }.to_not raise_error }
56
-
57
- it "should accept a hash of options" do
58
- expect{ TruncationExample.new {} }.to_not raise_error
59
- end
60
-
61
- it { expect{ TruncationExample.new( { :a_random_param => "should raise ArgumentError" } ) }.to raise_error(ArgumentError) }
62
- it { expect{ TruncationExample.new( { :except => "something",:only => "something else" } ) }.to raise_error(ArgumentError) }
63
- it { expect{ TruncationExample.new( { :only => "something" } ) }.to_not raise_error }
64
- it { expect{ TruncationExample.new( { :except => "something" } ) }.to_not raise_error }
65
- it { expect{ TruncationExample.new( { :pre_count => "something" } ) }.to_not raise_error }
66
- it { expect{ TruncationExample.new( { :reset_ids => "something" } ) }.to_not raise_error }
67
-
68
- context "" do
69
- subject { TruncationExample.new( { :only => ["something"] } ) }
70
- its(:only) { should eq ["something"] }
71
- its(:except) { should eq [] }
72
- end
73
-
74
- context "" do
75
- subject { TruncationExample.new( { :except => ["something"] } ) }
76
- its(:only) { should eq nil }
77
- its(:except) { should include("something") }
78
- end
79
-
80
- context "" do
81
- subject { TruncationExample.new( { :reset_ids => ["something"] } ) }
82
- its(:reset_ids?) { should eq true }
83
- end
84
-
85
- context "" do
86
- subject { TruncationExample.new( { :reset_ids => nil } ) }
87
- its(:reset_ids?) { should eq false }
88
- end
89
-
90
- context "" do
91
- subject { TruncationExample.new( { :pre_count => ["something"] } ) }
92
- its(:pre_count?) { should eq true }
93
- end
94
-
95
- context "" do
96
- subject { TruncationExample.new( { :pre_count => nil } ) }
97
- its(:pre_count?) { should eq false }
98
- end
99
-
100
- context "" do
101
- subject { MigrationExample.new }
102
- its(:only) { should eq nil }
103
- its(:except) { should eq %w[migration_storage_name] }
104
- end
105
-
106
- context "" do
107
- EXCEPT_TABLES = ["something"]
108
- subject { MigrationExample.new( { :except => EXCEPT_TABLES } ) }
109
-
110
- it "should not modify the array of excepted tables" do
111
- subject.except.should include("migration_storage_name")
112
- EXCEPT_TABLES.should_not include("migration_storage_name")
113
- end
114
- end
115
- end
116
- end
117
- end
118
- end
@@ -1,26 +0,0 @@
1
- module MongoTest
2
- class ThingBase
3
- def self.collection
4
- @connection ||= ::Mongo::Connection.new('127.0.0.1')
5
- @db ||= @connection.db('database_cleaner_specs')
6
- @mongo ||= @db.collection(name) || @db.create_collection(name)
7
- end
8
-
9
- def self.count
10
- @mongo.count
11
- end
12
-
13
- def initialize(attrs={})
14
- @attrs = attrs
15
- end
16
-
17
- def save!
18
- self.class.collection.insert(@attrs)
19
- end
20
- end
21
-
22
- class Widget < ThingBase
23
- end
24
- class Gadget < ThingBase
25
- end
26
- end