database_cleaner 1.7.0 → 1.8.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTE.markdown +1 -2
  3. data/Gemfile.lock +130 -91
  4. data/History.rdoc +1 -1
  5. data/README.markdown +71 -226
  6. data/Rakefile +12 -8
  7. data/adapters/database_cleaner-active_record/lib/database_cleaner-active_record.rb +1 -0
  8. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record.rb +6 -0
  9. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/base.rb +13 -4
  10. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/deletion.rb +19 -19
  11. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/transaction.rb +0 -0
  12. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/truncation.rb +22 -19
  13. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/version.rb +5 -0
  14. data/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb +1 -0
  15. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb +11 -0
  16. data/{lib → adapters/database_cleaner-couch_potato/lib}/database_cleaner/couch_potato/base.rb +0 -0
  17. data/{lib → adapters/database_cleaner-couch_potato/lib}/database_cleaner/couch_potato/truncation.rb +0 -0
  18. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb +5 -0
  19. data/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb +1 -0
  20. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb +4 -0
  21. data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/base.rb +4 -0
  22. data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/transaction.rb +0 -0
  23. data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/truncation.rb +4 -3
  24. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb +5 -0
  25. data/adapters/database_cleaner-mongo/lib/database_cleaner-mongo.rb +1 -0
  26. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb +10 -0
  27. data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/base.rb +0 -0
  28. data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/truncation.rb +0 -0
  29. data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/truncation_mixin.rb +0 -0
  30. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +5 -0
  31. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner-mongo_mapper.rb +1 -0
  32. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +4 -0
  33. data/{lib → adapters/database_cleaner-mongo_mapper/lib}/database_cleaner/mongo_mapper/base.rb +4 -0
  34. data/{lib → adapters/database_cleaner-mongo_mapper/lib}/database_cleaner/mongo_mapper/truncation.rb +0 -0
  35. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +5 -0
  36. data/adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb +1 -0
  37. data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongo2/truncation_mixin.rb +0 -0
  38. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +10 -0
  39. data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongoid/base.rb +0 -0
  40. data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongoid/truncation.rb +0 -0
  41. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +5 -0
  42. data/adapters/database_cleaner-moped/lib/database_cleaner-moped.rb +1 -0
  43. data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +10 -0
  44. data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/base.rb +1 -1
  45. data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/truncation.rb +0 -0
  46. data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/truncation_base.rb +4 -0
  47. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +5 -0
  48. data/adapters/database_cleaner-neo4j/lib/database_cleaner-neo4j.rb +1 -0
  49. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +6 -0
  50. data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/base.rb +4 -0
  51. data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/deletion.rb +0 -0
  52. data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/transaction.rb +0 -0
  53. data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/truncation.rb +0 -0
  54. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +5 -0
  55. data/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb +1 -0
  56. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +10 -0
  57. data/{lib → adapters/database_cleaner-ohm/lib}/database_cleaner/ohm/truncation.rb +4 -0
  58. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +5 -0
  59. data/adapters/database_cleaner-redis/lib/database_cleaner-redis.rb +1 -0
  60. data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +4 -0
  61. data/{lib → adapters/database_cleaner-redis/lib}/database_cleaner/redis/base.rb +4 -0
  62. data/{lib → adapters/database_cleaner-redis/lib}/database_cleaner/redis/truncation.rb +0 -0
  63. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +5 -0
  64. data/adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb +1 -0
  65. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel.rb +6 -0
  66. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/base.rb +4 -0
  67. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/deletion.rb +0 -0
  68. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/transaction.rb +0 -0
  69. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/truncation.rb +16 -15
  70. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +5 -0
  71. data/lib/database_cleaner.rb +36 -1
  72. data/lib/database_cleaner/base.rb +85 -103
  73. data/lib/database_cleaner/configuration.rb +93 -83
  74. data/lib/database_cleaner/deprecation.rb +21 -0
  75. data/lib/database_cleaner/null_strategy.rb +6 -6
  76. data/lib/database_cleaner/orm_autodetector.rb +31 -0
  77. data/lib/database_cleaner/safeguard.rb +38 -3
  78. data/lib/database_cleaner/spec.rb +2 -0
  79. data/lib/database_cleaner/spec/database_helper.rb +82 -0
  80. data/lib/database_cleaner/spec/shared_examples.rb +15 -0
  81. data/lib/database_cleaner/version.rb +3 -0
  82. metadata +111 -46
  83. data/VERSION.yml +0 -4
  84. data/lib/database_cleaner/mongo2/base.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a0ef67709709d9ad8373dbc723dc3c5b965766a7e48b40badf5d4392558a6bd
4
- data.tar.gz: 141f0a4e38d548ca0f100dd25f7c305cf459d87970eff5b8283d1a7b79eb0734
3
+ metadata.gz: f7075fc4af0869a88e8ee2682bcf7747fab56dd4e03f0c25d6029396d6e523e8
4
+ data.tar.gz: b9529e7d563d9b5c41e5b9b7fb4b61da47a04ffd4c5cdf196873c773b458e0ab
5
5
  SHA512:
6
- metadata.gz: f8161cfd306d227da75c2d997eeae124f191d9382b81a7e884ac43a5e272b4a931386427e700ef11af9f5416f6916c467c77104e46441b6b9a5e6329191c3516
7
- data.tar.gz: 52f01680d172a214fa97d9f495c644b329014c74e53c862aa7aa7c91c26b0ca0769e684632997c564a2001f60fc212e03dabca789e0b27b3d1a93d1cd964f5aa
6
+ metadata.gz: 4089ca709da78161339e9cd30f0d95fdd916a6298861e2c355dba8ca64eff1d38f9649a1e213fdad1cc654e156eebbb05b4b048e1ab46fb37f61a3980979db3d
7
+ data.tar.gz: 59120baea0b241d973ee73d5ee0463968e96b406f6ed247d211f0a478dda0128f235fcc7998132bb41c1599249fb64d47bdbe3b428c1ebada5631fd1e24ca0a9
@@ -11,8 +11,7 @@ upstream:
11
11
  ## 2. Make sure the tests run fine
12
12
 
13
13
  - `bundle install`
14
- - Copy `db/sample.config.yml` to `db/config.yml` and edit it
15
- - Make sure to create the databases specified in `db/config.yml`
14
+ - Copy `spec/support/sample.config.yml` to `spec/support/config.yml` and edit it
16
15
  - Run the tests with `bundle exec rspec`
17
16
 
18
17
  Note that if you don't have all the supported databases installed and running,
@@ -1,22 +1,51 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- database_cleaner (1.6.3)
4
+ database_cleaner (1.8.0.beta)
5
+
6
+ PATH
7
+ remote: adapters
8
+ specs:
9
+ database_cleaner-active_record (1.8.0.beta)
10
+ activerecord
11
+ database_cleaner (~> 1.8.0.beta)
12
+ database_cleaner-couch_potato (1.8.0.beta)
13
+ couch_potato
14
+ database_cleaner (~> 1.8.0.beta)
15
+ database_cleaner-data_mapper (1.8.0.beta)
16
+ database_cleaner (~> 1.8.0.beta)
17
+ datamapper
18
+ dm-transactions
19
+ database_cleaner-mongo (1.8.0.beta)
20
+ database_cleaner (~> 1.8.0.beta)
21
+ mongo
22
+ database_cleaner-mongo_mapper (1.8.0.beta)
23
+ database_cleaner (~> 1.8.0.beta)
24
+ mongo_mapper
25
+ database_cleaner-mongoid (1.8.0.beta)
26
+ database_cleaner (~> 1.8.0.beta)
27
+ database_cleaner-mongo (~> 1.8.0.beta)
28
+ mongoid
29
+ database_cleaner-moped (1.8.0.beta)
30
+ database_cleaner (~> 1.8.0.beta)
31
+ moped
32
+ database_cleaner-neo4j (1.8.0.beta)
33
+ database_cleaner (~> 1.8.0.beta)
34
+ neo4j-core
35
+ database_cleaner-ohm (1.8.0.beta)
36
+ database_cleaner (~> 1.8.0.beta)
37
+ database_cleaner-redis (~> 1.8.0.beta)
38
+ ohm
39
+ database_cleaner-redis (1.8.0.beta)
40
+ database_cleaner (~> 1.8.0.beta)
41
+ redis
42
+ database_cleaner-sequel (1.8.0.beta)
43
+ database_cleaner (~> 1.8.0.beta)
44
+ sequel
5
45
 
6
46
  GEM
7
47
  remote: https://rubygems.org/
8
48
  specs:
9
- abstract (1.0.0)
10
- actionpack (3.0.0)
11
- activemodel (= 3.0.0)
12
- activesupport (= 3.0.0)
13
- builder (~> 2.1.2)
14
- erubis (~> 2.6.6)
15
- i18n (~> 0.4.1)
16
- rack (~> 1.2.1)
17
- rack-mount (~> 0.6.12)
18
- rack-test (~> 0.5.4)
19
- tzinfo (~> 0.3.23)
20
49
  activemodel (3.0.0)
21
50
  activesupport (= 3.0.0)
22
51
  builder (~> 2.1.2)
@@ -38,20 +67,20 @@ GEM
38
67
  bcrypt (>= 3.1.3)
39
68
  bcrypt-ruby (3.1.5-java)
40
69
  bcrypt (>= 3.1.3)
41
- bson (1.11.1)
42
- bson (1.11.1-java)
43
- bson_ext (1.11.1)
44
- bson (~> 1.11.1)
70
+ bson (1.12.5)
71
+ bson (1.12.5-java)
72
+ bson_ext (1.12.5)
73
+ bson (~> 1.12.5)
45
74
  builder (2.1.2)
46
- coderay (1.1.0)
75
+ coderay (1.1.2)
47
76
  couch_potato (1.3.0)
48
77
  activemodel
49
78
  couchrest (~> 1.2.0)
50
79
  json (~> 1.6)
51
- couchrest (1.2.0)
52
- mime-types (~> 1.15)
53
- multi_json (~> 1.0)
54
- rest-client (~> 1.6.1)
80
+ couchrest (1.2.1)
81
+ mime-types (>= 1.15)
82
+ multi_json (~> 1.7, ~> 1.0)
83
+ rest-client (~> 1.8.0)
55
84
  cucumber (1.2.1)
56
85
  builder (>= 2.1.2)
57
86
  diff-lcs (>= 1.1.3)
@@ -69,7 +98,7 @@ GEM
69
98
  dm-transactions (~> 1.2.0)
70
99
  dm-types (~> 1.2.0)
71
100
  dm-validations (~> 1.2.0)
72
- diff-lcs (1.2.5)
101
+ diff-lcs (1.3)
73
102
  dm-aggregates (1.2.0)
74
103
  dm-core (~> 1.2.0)
75
104
  dm-constraints (1.2.0)
@@ -112,29 +141,36 @@ GEM
112
141
  data_objects (= 0.10.14)
113
142
  do_jdbc (= 0.10.14)
114
143
  jdbc-sqlite3 (>= 3.5.8)
115
- erubis (2.6.6)
116
- abstract (>= 1.0.0)
144
+ domain_name (0.5.20180417)
145
+ unf (>= 0.0.5, < 1.0.0)
117
146
  faraday (0.9.0)
118
147
  multipart-post (>= 1.2, < 3)
119
148
  faraday_middleware (0.9.1)
120
149
  faraday (>= 0.7.4, < 0.10)
121
150
  fastercsv (1.5.5)
122
- ffi (1.9.6)
123
- ffi (1.9.6-java)
151
+ ffi (1.9.25)
152
+ ffi (1.9.25-java)
124
153
  formatador (0.2.5)
125
154
  gherkin (2.11.6)
126
155
  json (>= 1.7.6)
127
156
  gherkin (2.11.6-java)
128
157
  json (>= 1.7.6)
129
- guard (1.8.3)
158
+ guard (2.14.2)
130
159
  formatador (>= 0.2.4)
131
- listen (~> 1.3)
132
- lumberjack (>= 1.0.2)
133
- pry (>= 0.9.10)
134
- thor (>= 0.14.6)
135
- guard-rspec (2.5.4)
136
- guard (>= 1.1)
137
- rspec (~> 2.11)
160
+ listen (>= 2.7, < 4.0)
161
+ lumberjack (>= 1.0.12, < 2.0)
162
+ nenv (~> 0.1)
163
+ notiffany (~> 0.0)
164
+ pry (>= 0.9.12)
165
+ shellany (~> 0.0)
166
+ thor (>= 0.18.1)
167
+ guard-compat (1.2.1)
168
+ guard-rspec (4.7.3)
169
+ guard (~> 2.1)
170
+ guard-compat (~> 1.1)
171
+ rspec (>= 2.99.0, < 4.0)
172
+ http-cookie (1.0.3)
173
+ domain_name (~> 0.5)
138
174
  httparty (0.13.3)
139
175
  json (~> 1.8)
140
176
  multi_xml (>= 0.5.2)
@@ -144,15 +180,14 @@ GEM
144
180
  json (1.8.6)
145
181
  json (1.8.6-java)
146
182
  json_pure (1.8.1)
147
- listen (1.3.1)
148
- rb-fsevent (>= 0.9.3)
149
- rb-inotify (>= 0.9)
150
- rb-kqueue (>= 0.2)
151
- lumberjack (1.0.9)
152
- method_source (0.8.2)
153
- mime-types (1.25.1)
154
- mongo (1.11.1)
155
- bson (= 1.11.1)
183
+ listen (3.0.8)
184
+ rb-fsevent (~> 0.9, >= 0.9.4)
185
+ rb-inotify (~> 0.9, >= 0.9.7)
186
+ lumberjack (1.0.13)
187
+ method_source (0.9.0)
188
+ mime-types (2.99.3)
189
+ mongo (1.12.5)
190
+ bson (= 1.12.5)
156
191
  mongo_ext (0.19.3)
157
192
  mongo_mapper (0.12.0)
158
193
  activemodel (~> 3.0)
@@ -165,11 +200,12 @@ GEM
165
200
  mongoid-tree (0.7.0)
166
201
  mongoid (~> 2.0)
167
202
  moped (1.5.2)
168
- multi_json (1.2.0)
203
+ multi_json (1.13.1)
169
204
  multi_xml (0.5.5)
170
205
  multipart-post (2.0.0)
171
206
  mysql (2.9.1)
172
207
  mysql2 (0.3.18)
208
+ nenv (0.3.0)
173
209
  neo4j-community (2.1.5)
174
210
  neo4j-core (3.0.8)
175
211
  activesupport
@@ -185,67 +221,57 @@ GEM
185
221
  nest (1.1.2)
186
222
  redis
187
223
  net-http-persistent (2.9.4)
224
+ netrc (0.11.0)
225
+ notiffany (0.1.1)
226
+ nenv (~> 0.1)
227
+ shellany (~> 0.0)
188
228
  ohm (0.1.5)
189
229
  nest (~> 1.0)
190
230
  os (0.9.6)
191
231
  pg (0.18.2)
192
232
  plucky (0.5.2)
193
233
  mongo (~> 1.5)
194
- pry (0.10.1)
234
+ pry (0.11.3)
195
235
  coderay (~> 1.1.0)
196
- method_source (~> 0.8.1)
197
- slop (~> 3.4)
198
- pry (0.10.1-java)
236
+ method_source (~> 0.9.0)
237
+ pry (0.11.3-java)
199
238
  coderay (~> 1.1.0)
200
- method_source (~> 0.8.1)
201
- slop (~> 3.4)
239
+ method_source (~> 0.9.0)
202
240
  spoon (~> 0.0)
203
- rack (1.2.8)
204
- rack-mount (0.6.14)
205
- rack (>= 1.0.0)
206
- rack-test (0.5.7)
207
- rack (>= 1.0)
208
- railties (3.0.0)
209
- actionpack (= 3.0.0)
210
- activesupport (= 3.0.0)
211
- rake (>= 0.8.4)
212
- thor (~> 0.14.0)
213
241
  rake (11.1.2)
214
- rb-fsevent (0.9.4)
215
- rb-inotify (0.9.5)
216
- ffi (>= 0.5.0)
217
- rb-kqueue (0.2.3)
218
- ffi (>= 0.5.0)
219
- rdoc (4.1.2)
220
- json (~> 1.4)
242
+ rb-fsevent (0.10.3)
243
+ rb-inotify (0.9.10)
244
+ ffi (>= 0.5.0, < 2)
221
245
  redis (3.1.0)
222
- rest-client (1.6.8)
223
- mime-types (~> 1.16)
224
- rdoc (>= 2.4.2)
225
- rspec (2.14.1)
226
- rspec-core (~> 2.14.0)
227
- rspec-expectations (~> 2.14.0)
228
- rspec-mocks (~> 2.14.0)
229
- rspec-core (2.14.8)
230
- rspec-expectations (2.14.5)
231
- diff-lcs (>= 1.1.3, < 2.0)
232
- rspec-mocks (2.14.6)
233
- rspec-rails (2.14.2)
234
- actionpack (>= 3.0)
235
- activemodel (>= 3.0)
236
- activesupport (>= 3.0)
237
- railties (>= 3.0)
238
- rspec-core (~> 2.14.0)
239
- rspec-expectations (~> 2.14.0)
240
- rspec-mocks (~> 2.14.0)
246
+ rest-client (1.8.0)
247
+ http-cookie (>= 1.0.2, < 2.0)
248
+ mime-types (>= 1.16, < 3.0)
249
+ netrc (~> 0.7)
250
+ rspec (3.7.0)
251
+ rspec-core (~> 3.7.0)
252
+ rspec-expectations (~> 3.7.0)
253
+ rspec-mocks (~> 3.7.0)
254
+ rspec-core (3.7.1)
255
+ rspec-support (~> 3.7.0)
256
+ rspec-expectations (3.7.0)
257
+ diff-lcs (>= 1.2.0, < 2.0)
258
+ rspec-support (~> 3.7.0)
259
+ rspec-mocks (3.7.0)
260
+ diff-lcs (>= 1.2.0, < 2.0)
261
+ rspec-support (~> 3.7.0)
262
+ rspec-support (3.7.1)
241
263
  sequel (3.21.0)
242
- slop (3.6.0)
243
- spoon (0.0.4)
264
+ shellany (0.0.1)
265
+ spoon (0.0.6)
244
266
  ffi
245
267
  sqlite3 (1.3.10)
246
268
  stringex (1.5.1)
247
- thor (0.14.6)
269
+ thor (0.20.0)
248
270
  tzinfo (0.3.48)
271
+ unf (0.1.4)
272
+ unf_ext
273
+ unf (0.1.4-java)
274
+ unf_ext (0.0.7.5)
249
275
  uuidtools (2.1.5)
250
276
  zip (2.0.2)
251
277
 
@@ -261,11 +287,24 @@ DEPENDENCIES
261
287
  couch_potato
262
288
  cucumber
263
289
  database_cleaner!
290
+ database_cleaner-active_record!
291
+ database_cleaner-couch_potato!
292
+ database_cleaner-data_mapper!
293
+ database_cleaner-mongo!
294
+ database_cleaner-mongo_mapper!
295
+ database_cleaner-mongoid!
296
+ database_cleaner-moped!
297
+ database_cleaner-neo4j!
298
+ database_cleaner-ohm!
299
+ database_cleaner-redis!
300
+ database_cleaner-sequel!
264
301
  datamapper
265
302
  dm-migrations
266
303
  dm-sqlite-adapter
267
304
  guard-rspec
268
305
  json_pure
306
+ listen (~> 3.0.0)
307
+ mongo (~> 1.12.0)
269
308
  mongo_ext
270
309
  mongo_mapper
271
310
  mongoid
@@ -277,10 +316,10 @@ DEPENDENCIES
277
316
  ohm (~> 0.1.3)
278
317
  pg
279
318
  rake
280
- rspec-rails (~> 2.14.2)
319
+ rspec
281
320
  sequel (~> 3.21.0)
282
321
  sqlite3
283
322
  tzinfo
284
323
 
285
324
  BUNDLED WITH
286
- 1.15.0
325
+ 1.17.3
@@ -3,7 +3,7 @@
3
3
  === Bug Fixes
4
4
  === Changes
5
5
 
6
- == 1.7.0 2017-04-19
6
+ == 1.7.0 2018-04-19
7
7
 
8
8
  === Bug Fixes
9
9
  * Remove unnecessary folders from gem: https://github.com/DatabaseCleaner/database_cleaner/pull/508
@@ -1,149 +1,73 @@
1
+ **If you're viewing this at https://github.com/DatabaseCleaner/database_cleaner,
2
+ you're reading the documentation for the `master` branch.
3
+ [View documentation for the latest release
4
+ (1.7.0).](https://github.com/DatabaseCleaner/database_cleaner/blob/v1.7.0/README.markdown)**
5
+
1
6
  # Database Cleaner
2
7
 
3
8
  [![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner)
4
9
  [![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner)
5
10
 
6
- Database Cleaner is a set of strategies for cleaning your database in Ruby.
11
+ Database Cleaner is a set of gems containing strategies for cleaning your database in Ruby.
7
12
 
8
13
  The original use case was to ensure a clean state during tests.
9
14
  Each strategy is a small amount of code but is code that is usually needed in any ruby app that is testing with a database.
10
15
 
11
16
  ## Gem Setup
12
17
 
18
+ Instead of using the `database_cleaner` gem directly, each ORM has its own gem. Most projects will only need the `database_cleaner-active_record` gem:
19
+
13
20
  ```ruby
14
21
  # Gemfile
15
22
  group :test do
16
- gem 'database_cleaner'
23
+ gem 'database_cleaner-active_record'
17
24
  end
18
25
  ```
19
26
 
20
- ## Supported Databases, Libraries and Strategies
21
-
22
- ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, CouchPotato, Ohm and Redis are supported.
23
-
24
- Here is an overview of the strategies supported for each library:
25
-
26
- <table>
27
- <tbody>
28
- <tr>
29
- <th>ORM</th>
30
- <th>Truncation</th>
31
- <th>Transaction</th>
32
- <th>Deletion</th>
33
- </tr>
34
- <tr>
35
- <td> ActiveRecord </td>
36
- <td> Yes</td>
37
- <td> <b>Yes</b></td>
38
- <td> Yes</td>
39
- </tr>
40
- <tr>
41
- <td> DataMapper</td>
42
- <td> Yes</td>
43
- <td> <b>Yes</b></td>
44
- <td> No</td>
45
- </tr>
46
- <tr>
47
- <td> CouchPotato</td>
48
- <td> <b>Yes</b></td>
49
- <td> No</td>
50
- <td> No</td>
51
- </tr>
52
- <tr>
53
- <td> MongoMapper</td>
54
- <td> <b>Yes</b></td>
55
- <td> No</td>
56
- <td> No</td>
57
- </tr>
58
- <tr>
59
- <td> Mongoid</td>
60
- <td> <b>Yes</b></td>
61
- <td> No</td>
62
- <td> No</td>
63
- </tr>
64
- <tr>
65
- <td> Sequel</td>
66
- <td> <b>Yes</b></td>
67
- <td> Yes</td>
68
- <td> Yes</td>
69
- </tr>
70
- <tr>
71
- <td>Redis</td>
72
- <td><b>Yes</b></td>
73
- <td>No</td>
74
- <td>No</td>
75
- </tr>
76
- <tr>
77
- <td>Ohm</td>
78
- <td><b>Yes</b></td>
79
- <td>No</td>
80
- <td>No</td>
81
- </tr>
82
- <tr>
83
- <td>Neo4j</td>
84
- <td>Yes</td>
85
- <td>Yes*</td>
86
- <td>Yes*</td>
87
- </tr>
88
- </tbody>
89
- </table>
90
-
91
- \* Truncation and Deletion strategies for Neo4j will just delete all nodes and relationships from the database.
92
-
93
- <table>
94
- <tbody>
95
- <tr>
96
- <th>Driver</th>
97
- <th>Truncation</th>
98
- <th>Transaction</th>
99
- <th>Deletion</th>
100
- </tr>
101
- <tr>
102
- <td> Mongo</td>
103
- <td> Yes</td>
104
- <td> No</td>
105
- <td> No</td>
106
- </tr>
107
- <tr>
108
- <td> Moped</td>
109
- <td> Yes</td>
110
- <td> No</td>
111
- <td> No</td>
112
- </tr>
113
- </tbody>
114
- </table>
115
-
116
- (Default strategy for each library is denoted in bold)
117
-
118
- Database Cleaner also includes a `null` strategy (that does no cleaning at all) which can be used with any ORM library.
119
- You can also explicitly use it by setting your strategy to `nil`.
27
+ If you are using multiple ORMs, just load multiple gems:
120
28
 
121
- For support or to discuss development please use the [Google Group](http://groups.google.com/group/database_cleaner).
122
29
 
123
- ## What strategy is fastest?
30
+ ```ruby
31
+ # Gemfile
32
+ group :test do
33
+ gem 'database_cleaner-active_record'
34
+ gem 'database_cleaner-redis'
35
+ end
36
+ ```
124
37
 
125
- For the SQL libraries the fastest option will be to use `:transaction` as transactions are simply rolled back. If you can use this strategy you should. However, if you wind up needing to use multiple database connections in your tests (i.e. your tests run in a different process than your application) then using this strategy becomes a bit more difficult. You can get around the problem a number of ways.
38
+ ## List of adapters
126
39
 
127
- One common approach is to force all processes to use the same database connection ([common ActiveRecord hack](http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/)) however this approach has been reported to result in non-deterministic failures.
40
+ Here is an overview of the databases and ORMs supported by each adapter:
128
41
 
129
- Another approach is to have the transactions rolled back in the application's process and relax the isolation level of the database (so the tests can read the uncommitted transactions).
42
+ MySQL, PostgreSQL, SQLite, etc
43
+ * [database_cleaner-active_record](adapters/database_cleaner-active_record)
44
+ * [database_cleaner-sequel](adapters/database_cleaner-sequel)
45
+ * [database_cleaner-data_mapper](adapters/database_cleaner-data_mapper)
130
46
 
131
- An easier, but slower, solution is to use the `:truncation` or `:deletion` strategy.
47
+ CouchDB
48
+ * [database_cleaner-couch_potato](adapters/database_cleaner-couch_potato)
132
49
 
133
- So what is fastest out of `:deletion` and `:truncation`? Well, it depends on your table structure and what percentage of tables you populate in an average test. The reasoning is out of the scope of this README but here is a [good SO answer on this topic for Postgres](http://stackoverflow.com/questions/11419536/postgresql-truncation-speed/11423886#11423886).
50
+ MongoDB
51
+ * [database_cleaner-mongoid](adapters/database_cleaner-mongoid)
52
+ * [database_cleaner-mongo_mapper](adapters/database_cleaner-mongo_mapper)
53
+ * [database_cleaner-moped](adapters/database_cleaner-moped)
54
+ * [database_cleaner-mongo](adapters/database_cleaner-mongo)
134
55
 
135
- Some people report much faster speeds with `:deletion` while others say `:truncation` is faster for them. The best approach therefore is it try all options on your test suite and see what is faster.
56
+ Redis
57
+ * [database_cleaner-redis](adapters/database_cleaner-redis)
58
+ * [database_cleaner-ohm](adapters/database_cleaner-ohm)
136
59
 
137
- If you are using ActiveRecord then take a look at the [additional options](#additional-activerecord-options-for-truncation) available for `:truncation`.
60
+ Neo4j
61
+ * [database_cleaner-neo4j](adapters/database_cleaner-neo4j)
138
62
 
139
- ## Dependencies
63
+ More details on available configuration options can be found in the README for the specific adapter gem that you're using.
140
64
 
141
- Because database_cleaner supports multiple ORMs, it doesn't make sense to include all the dependencies for each one in the gemspec. However, the DataMapper adapter does depend on dm-transactions. Therefore, if you use DataMapper, you must include dm-transactions in your Gemfile/bundle/gemset manually.
65
+ For support or to discuss development please use the [Google Group](https://groups.google.com/group/database_cleaner).
142
66
 
143
67
  ## How to use
144
68
 
145
69
  ```ruby
146
- require 'database_cleaner'
70
+ require 'database_cleaner/active_record'
147
71
 
148
72
  DatabaseCleaner.strategy = :truncation
149
73
 
@@ -161,15 +85,12 @@ DatabaseCleaner.strategy = :truncation, {:only => %w[widgets dogs some_other_tab
161
85
  DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
162
86
  ```
163
87
 
164
- With Ohm and Redis, `:only` and `:except` take a list of strings to be
165
- passed to [`keys`](http://redis.io/commands/keys)).
166
-
167
88
  (I should point out the truncation strategy will never truncate your schema_migrations table.)
168
89
 
169
90
  Some strategies need to be started before tests are run (for example the `:transaction` strategy needs to know to open up a transaction). This can be accomplished by calling `DatabaseCleaner.start` at the beginning of the run, or by running the tests inside a block to `DatabaseCleaner.cleaning`. So you would have:
170
91
 
171
92
  ```ruby
172
- require 'database_cleaner'
93
+ require 'database_cleaner/active_record'
173
94
 
174
95
  DatabaseCleaner.strategy = :transaction
175
96
 
@@ -191,7 +112,7 @@ At times you may want to do a single clean with one strategy.
191
112
  For example, you may want to start the process by truncating all the tables, but then use the faster transaction strategy the remaining time. To accomplish this you can say:
192
113
 
193
114
  ```ruby
194
- require 'database_cleaner'
115
+ require 'database_cleaner/active_record'
195
116
 
196
117
  DatabaseCleaner.clean_with :truncation
197
118
 
@@ -200,17 +121,26 @@ DatabaseCleaner.strategy = :transaction
200
121
  # then make the DatabaseCleaner.start and DatabaseCleaner.clean calls appropriately
201
122
  ```
202
123
 
203
- ### Additional ActiveRecord options for Truncation
124
+ ## What strategy is fastest?
125
+
126
+ For the SQL libraries the fastest option will be to use `:transaction` as transactions are simply rolled back. If you can use this strategy you should. However, if you wind up needing to use multiple database connections in your tests (i.e. your tests run in a different process than your application) then using this strategy becomes a bit more difficult. You can get around the problem a number of ways.
127
+
128
+ One common approach is to force all processes to use the same database connection ([common ActiveRecord hack](http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/)) however this approach has been reported to result in non-deterministic failures.
129
+
130
+ Another approach is to have the transactions rolled back in the application's process and relax the isolation level of the database (so the tests can read the uncommitted transactions).
131
+
132
+ An easier, but slower, solution is to use the `:truncation` or `:deletion` strategy.
204
133
 
205
- The following options are available for ActiveRecord's `:truncation` strategy _only_ for MySQL and Postgres.
134
+ So what is fastest out of `:deletion` and `:truncation`? Well, it depends on your table structure and what percentage of tables you populate in an average test. The reasoning is out of the scope of this README but here is a [good SO answer on this topic for Postgres](https://stackoverflow.com/questions/11419536/postgresql-truncation-speed/11423886#11423886).
206
135
 
207
- * `:pre_count` - When set to `true` this will check each table for existing rows before truncating it. This can speed up test suites when many of the tables to be truncated are never populated. Defaults to `:false`. (Also, see the section on [What strategy is fastest?](#what-strategy-is-fastest))
208
- * `:reset_ids` - This only matters when `:pre_count` is used, and it will make sure that a tables auto-incrementing id is reset even if there are no rows in the table (e.g. records were created in the test but also removed before DatabaseCleaner gets to it). Defaults to `true`.
136
+ Some people report much faster speeds with `:deletion` while others say `:truncation` is faster for them. The best approach therefore is it try all options on your test suite and see what is faster.
209
137
 
210
- The following option is available for ActiveRecord's `:truncation` and `:deletion` strategy for any DB.
138
+ If you are using ActiveRecord then take a look at the [additional options](#additional-activerecord-options-for-truncation) available for `:truncation`.
211
139
 
212
- * `:cache_tables` - When set to `true` the list of tables to truncate or delete from will only be read from the DB once, otherwise it will be read before each cleanup run. Set this to `false` if (1) you create and drop tables in your tests, or (2) you change Postgres schemas (`ActiveRecord::Base.connection.schema_search_path`) in your tests (for example, in a multitenancy setup with each tenant in a different Postgres schema). Defaults to `true`.
140
+ Database Cleaner also includes a `null` strategy (that does no cleaning at all) which can be used with any ORM library.
141
+ You can also explicitly use it by setting your strategy to `nil`.
213
142
 
143
+ ## Test Framework Examples
214
144
 
215
145
  ### RSpec Example
216
146
 
@@ -345,14 +275,9 @@ If you're using Cucumber with Rails, just use the generator that ships with cucu
345
275
  Otherwise, to add DatabaseCleaner to your project by hand, create a file `features/support/database_cleaner.rb` that looks like this:
346
276
 
347
277
  ```ruby
348
- begin
349
- require 'database_cleaner'
350
- require 'database_cleaner/cucumber'
278
+ require 'database_cleaner/active_record'
351
279
 
352
- DatabaseCleaner.strategy = :truncation
353
- rescue NameError
354
- raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
355
- end
280
+ DatabaseCleaner.strategy = :truncation
356
281
 
357
282
  Around do |scenario, block|
358
283
  DatabaseCleaner.cleaning(&block)
@@ -370,11 +295,14 @@ Sometimes you need to use multiple ORMs in your application.
370
295
  You can use DatabaseCleaner to clean multiple ORMs, and multiple connections for those ORMs.
371
296
 
372
297
  ```ruby
373
- #How to specify particular orms
298
+ require 'database_cleaner/active_record'
299
+ require 'database_cleaner/mongo_mapper'
300
+
301
+ # How to specify particular orms
374
302
  DatabaseCleaner[:active_record].strategy = :transaction
375
303
  DatabaseCleaner[:mongo_mapper].strategy = :truncation
376
304
 
377
- #How to specify particular connections
305
+ # How to specify particular connections
378
306
  DatabaseCleaner[:active_record, { :connection => :two }]
379
307
 
380
308
  # You may also pass in the model directly:
@@ -383,68 +311,6 @@ DatabaseCleaner[:active_record, { :model => ModelWithDifferentConnection }]
383
311
 
384
312
  Usage beyond that remains the same with `DatabaseCleaner.start` calling any setup on the different configured connections, and `DatabaseCleaner.clean` executing afterwards.
385
313
 
386
- ### Configuration options
387
-
388
- <table>
389
- <tbody>
390
- <tr>
391
- <th>ORM</th>
392
- <th>How to access</th>
393
- <th>Notes</th>
394
- </tr>
395
- <tr>
396
- <td> Active Record </td>
397
- <td> <code>DatabaseCleaner[:active_record]</code></td>
398
- <td> Connection specified as <code>:symbol</code> keys, loaded from <code>config/database.yml</code>. You may also pass in the ActiveRecord model under the <code>:model</code> key.</td>
399
- </tr>
400
- <tr>
401
- <td> Data Mapper</td>
402
- <td> <code>DatabaseCleaner[:data_mapper]</code></td>
403
- <td> Connection specified as <code>:symbol</code> keys, loaded via Datamapper repositories </td>
404
- </tr>
405
- <tr>
406
- <td> Mongo Mapper</td>
407
- <td> <code>DatabaseCleaner[:mongo_mapper]</code></td>
408
- <td> Multiple connections not yet supported</td>
409
- </tr>
410
- <tr>
411
- <td> Mongoid</td>
412
- <td> <code>DatabaseCleaner[:mongoid]</code></td>
413
- <td> Multiple databases supported for Mongoid 3. Specify <code>DatabaseCleaner[:mongoid, {:connection =&gt; :db_name}]</code> </td>
414
- </tr>
415
- <tr>
416
- <td> Moped</td>
417
- <td> <code>DatabaseCleaner[:moped]</code></td>
418
- <td> It is necessary to configure database name with <code>DatabaseCleaner[:moped].db = db_name</code> otherwise name `default` will be used.</td>
419
- </tr>
420
- <tr>
421
- <td> Couch Potato</td>
422
- <td> <code>DatabaseCleaner[:couch_potato]</code></td>
423
- <td> Multiple connections not yet supported</td>
424
- </tr>
425
- <tr>
426
- <td> Sequel</td>
427
- <td> <code>DatabaseCleaner[:sequel]</code></td>
428
- <td> Multiple databases supported; specify <code>DatabaseCleaner[:sequel, {:connection =&gt; Sequel.connect(uri)}]</code></td>
429
- </tr>
430
- <tr>
431
- <td>Redis</td>
432
- <td><code>DatabaseCleaner[:redis]</code></td>
433
- <td>Connection specified as Redis URI</td>
434
- </tr>
435
- <tr>
436
- <td>Ohm</td>
437
- <td><code>DatabaseCleaner[:ohm]</code></td>
438
- <td>Connection specified as Redis URI</td>
439
- </tr>
440
- <tr>
441
- <td>Neo4j</td>
442
- <td><code>DatabaseCleaner[:neo4j]</code></td>
443
- <td>Database type and path(URI) <code>DatabaseCleaner[:neo4j, connection: {type: :server_db, path: 'http://localhost:7475'}].</code></td>
444
- </tr>
445
- </tbody>
446
- </table>
447
-
448
314
  ## Why?
449
315
 
450
316
  One of my motivations for writing this library was to have an easy way to turn on what Rails calls "transactional_fixtures" in my non-rails ActiveRecord projects.
@@ -455,15 +321,15 @@ After copying and pasting code to do this several times I decided to package it
455
321
 
456
322
  #### DatabaseCleaner is trying to use the wrong ORM
457
323
 
458
- DatabaseCleaner has an autodetect mechanism where if you do not explicitly define your ORM it will use the first ORM it can detect that is loaded.
324
+ DatabaseCleaner has a deprecated autodetect mechanism where if you do not explicitly define your ORM it will use the first ORM it can detect that is loaded.
459
325
 
460
326
  Since ActiveRecord is the most common ORM used that is the first one checked for.
461
327
 
462
- Sometimes other libraries (e.g. ActiveAdmin) will load other ORMs (e.g. ActiveRecord) even though you are using a different ORM. This will result in DatabaseCleaner trying to use the wrong ORM (e.g. ActiveRecord) unless you explicitly define your ORM like so:
328
+ Sometimes other libraries (e.g. ActiveAdmin) will load other ORMs (e.g. ActiveRecord) even though you are using a different ORM. This will result in DatabaseCleaner trying to use the wrong ORM (e.g. ActiveRecord) unless you explicitly require the correct adapter gem:
463
329
 
464
330
  ```ruby
465
- # How to setup your ORM explicitly
466
- DatabaseCleaner[:mongoid].strategy = :truncation
331
+ # Gemfile
332
+ gem "database_cleaner-mongoid"
467
333
  ```
468
334
 
469
335
  ### STDERR is being flooded when using Postgres
@@ -485,29 +351,12 @@ test:
485
351
  min_messages: WARNING
486
352
  </pre>
487
353
 
488
- ### Nothing happens in JRuby with Sequel using transactions
489
-
490
- Due to an inconsistency in JRuby's implementation of Fibers, Sequel gives a different connection to `DatabaseCleaner.start` than is used for tests run between `.start` and `.clean`. This can be worked around by running your tests in a block like `DatabaseCleaner.cleaning { run_my_tests }` instead, which does not use Fibers.
491
-
492
- ### Model fails to load with Neo4j using transactions
493
-
494
- When you are using [neo4j](https://github.com/neo4jrb/neo4j) gem it creates schema and reads indexes upon loading models. These operations can't be done during a transaction. You have to preload your models before DatabaseCleaner starts a transaction.
495
-
496
- Add to your rails_helper or spec_helper after requiring database_cleaner:
497
-
498
- ```ruby
499
- require 'database_cleaner'
500
- Dir["#{Rails.root}/app/models/**/*.rb"].each do |model|
501
- load model
502
- end
503
- ```
504
-
505
354
  ## Safeguards
506
355
 
507
356
  DatabaseCleaner comes with safeguards against:
508
357
 
509
358
  * Running in production (checking for `ENV`, `RACK_ENV`, and `RAILS_ENV`)
510
- * Running against a remote database (checking for a `DATABASE_URL` that does not include `localhost`)
359
+ * Running against a remote database (checking for a `DATABASE_URL` that does not include `localhost`, `.local` or `127.0.0.1`)
511
360
 
512
361
  Both safeguards can be disabled separately as follows.
513
362
 
@@ -525,17 +374,13 @@ DatabaseCleaner.allow_production = true
525
374
  DatabaseCleaner.allow_remote_database_url = true
526
375
  ```
527
376
 
528
- ## Debugging
529
-
530
- In rare cases DatabaseCleaner will encounter errors that it will log. By default it uses STDOUT set to the ERROR level but you can configure this to use whatever Logger you desire.
531
-
532
- Here's an example of using the `Rails.logger` in `env.rb`:
377
+ In Ruby, a URL whitelist can be specified. When specified, DatabaseCleaner will only allow `DATABASE_URL` to be equal
378
+ to one of the values specified in the url whitelist like so:
533
379
 
534
380
  ```ruby
535
- DatabaseCleaner.logger = Rails.logger
381
+ DatabaseCleaner.url_whitelist = ['postgres://postgres@localhost', 'postgres://foo@bar']
536
382
  ```
537
383
 
538
-
539
384
  ## COPYRIGHT
540
385
 
541
- Copyright (c) 2014 Ben Mabey. See LICENSE for details.
386
+ See [LICENSE] for details.