database_cleaner 1.8.1 → 1.99.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +24 -25
- data/History.rdoc +42 -1
- data/README.markdown +5 -3
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/truncation.rb +11 -1
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/version.rb +1 -1
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb +2 -0
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb +1 -1
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb +2 -0
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb +1 -1
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb +1 -0
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/base.rb +1 -1
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/deletion.rb +8 -0
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation.rb +18 -6
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +1 -1
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +1 -0
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb +19 -3
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +1 -1
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +1 -0
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/base.rb +1 -1
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/deletion.rb +10 -0
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb +26 -0
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/{mongo2/truncation_mixin.rb → mongoid/mongo2_truncation_mixin.rb} +3 -4
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb +65 -0
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/truncation.rb +6 -6
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +1 -1
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +2 -0
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +1 -1
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +1 -0
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +1 -1
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +2 -0
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb +6 -1
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +1 -1
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +1 -0
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/base.rb +7 -3
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/deletion.rb +9 -0
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/truncation.rb +1 -1
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +1 -1
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +1 -1
- data/lib/database_cleaner/base.rb +31 -11
- data/lib/database_cleaner/configuration.rb +5 -10
- data/lib/database_cleaner/deprecation.rb +5 -0
- data/lib/database_cleaner/orm_autodetector.rb +1 -0
- data/lib/database_cleaner/version.rb +1 -1
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93b54f2cfbd9e2d5dd08dd667ef971edaa28eecebbcff63b8f8afe464dd58aaa
|
4
|
+
data.tar.gz: 878b944b61afbf9d41ac619864e3fddf6ea7463da29e86ee946403ae7ab383f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 071f21db72ba854d2ccb2d23e82369347c6740c76045fee3f9ae8931ca62b50f612d91a74998491d385a0e270f3d7e7689eadbe81ec4c0eec94de852ecbd410d
|
7
|
+
data.tar.gz: 0b42bf542aafc6890ca4fe5d7408eddd95cfc822031bdb6b1100547ba6f96006ed7f68eb175f1f306f9fda9a49eb049b7928fd21d28bab4aac3f7d61678bce05
|
data/Gemfile.lock
CHANGED
@@ -1,46 +1,45 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
database_cleaner (1.
|
4
|
+
database_cleaner (1.99.0.beta)
|
5
5
|
|
6
6
|
PATH
|
7
7
|
remote: adapters
|
8
8
|
specs:
|
9
|
-
database_cleaner-active_record (1.
|
9
|
+
database_cleaner-active_record (1.99.0.beta)
|
10
10
|
activerecord
|
11
|
-
database_cleaner (~> 1.
|
12
|
-
database_cleaner-couch_potato (1.
|
11
|
+
database_cleaner (~> 1.99.0.beta)
|
12
|
+
database_cleaner-couch_potato (1.99.0.beta)
|
13
13
|
couch_potato
|
14
|
-
database_cleaner (~> 1.
|
15
|
-
database_cleaner-data_mapper (1.
|
16
|
-
database_cleaner (~> 1.
|
14
|
+
database_cleaner (~> 1.99.0.beta)
|
15
|
+
database_cleaner-data_mapper (1.99.0.beta)
|
16
|
+
database_cleaner (~> 1.99.0.beta)
|
17
17
|
datamapper
|
18
18
|
dm-transactions
|
19
|
-
database_cleaner-mongo (1.
|
20
|
-
database_cleaner (~> 1.
|
19
|
+
database_cleaner-mongo (1.99.0.beta)
|
20
|
+
database_cleaner (~> 1.99.0.beta)
|
21
21
|
mongo
|
22
|
-
database_cleaner-mongo_mapper (1.
|
23
|
-
database_cleaner (~> 1.
|
22
|
+
database_cleaner-mongo_mapper (1.99.0.beta)
|
23
|
+
database_cleaner (~> 1.99.0.beta)
|
24
24
|
mongo_mapper
|
25
|
-
database_cleaner-mongoid (1.
|
26
|
-
database_cleaner (~> 1.
|
27
|
-
database_cleaner-mongo (~> 1.8.0)
|
25
|
+
database_cleaner-mongoid (1.99.0.beta)
|
26
|
+
database_cleaner (~> 1.99.0.beta)
|
28
27
|
mongoid
|
29
|
-
database_cleaner-moped (1.
|
30
|
-
database_cleaner (~> 1.
|
28
|
+
database_cleaner-moped (1.99.0.beta)
|
29
|
+
database_cleaner (~> 1.99.0.beta)
|
31
30
|
moped
|
32
|
-
database_cleaner-neo4j (1.
|
33
|
-
database_cleaner (~> 1.
|
31
|
+
database_cleaner-neo4j (1.99.0.beta)
|
32
|
+
database_cleaner (~> 1.99.0.beta)
|
34
33
|
neo4j-core
|
35
|
-
database_cleaner-ohm (1.
|
36
|
-
database_cleaner (~> 1.
|
37
|
-
database_cleaner-redis (~> 1.
|
34
|
+
database_cleaner-ohm (1.99.0.beta)
|
35
|
+
database_cleaner (~> 1.99.0.beta)
|
36
|
+
database_cleaner-redis (~> 1.99.0.beta)
|
38
37
|
ohm
|
39
|
-
database_cleaner-redis (1.
|
40
|
-
database_cleaner (~> 1.
|
38
|
+
database_cleaner-redis (1.99.0.beta)
|
39
|
+
database_cleaner (~> 1.99.0.beta)
|
41
40
|
redis
|
42
|
-
database_cleaner-sequel (1.
|
43
|
-
database_cleaner (~> 1.
|
41
|
+
database_cleaner-sequel (1.99.0.beta)
|
42
|
+
database_cleaner (~> 1.99.0.beta)
|
44
43
|
sequel
|
45
44
|
|
46
45
|
GEM
|
data/History.rdoc
CHANGED
@@ -1,6 +1,47 @@
|
|
1
|
-
==
|
1
|
+
== 1.99.0 (v1-maintenance)
|
2
|
+
|
3
|
+
== Changes
|
4
|
+
* Remove unnecessary dependency on database_cleaner-mongo from database_cleaner-mongoid: @botandrose
|
5
|
+
* Enable the :cache_tables option for the mongo truncation strategy, and default to true: https://github.com/DatabaseCleaner/database_cleaner/pull/646"
|
6
|
+
* Introduce deletion aliases for truncation strategies for mongo, mongoid, and redis adapters. https://github.com/DatabaseCleaner/database_cleaner/pull/654
|
7
|
+
* Add new :db orm configuration key, for consistency with #db and #db=. https://github.com/DatabaseCleaner/database_cleaner/pull/649
|
8
|
+
|
9
|
+
== Deprecations
|
10
|
+
* Deprecate all #orm= setter methods: https://github.com/DatabaseCleaner/database_cleaner/pull/643
|
11
|
+
* Deprecate non-functional :reset_ids option in ActiveRecord truncation strategy: https://github.com/DatabaseCleaner/database_cleaner/issues/559
|
12
|
+
* Deprecate mongo truncation's `:cache_tables => true` option in favor of `false`, to prep for caching removal in v2.0: https://github.com/DatabaseCleaner/database_cleaner/pull/646"
|
13
|
+
* Deprecate redis truncation's #url method in favor of #db: @botandrose
|
14
|
+
* Deprecate mongo, mongoid, and redis truncation strategies in favor of deletion. https://github.com/DatabaseCleaner/database_cleaner/pull/654
|
15
|
+
* Deprecate :connection and :model configuration options in favor of :db for consistency: https://github.com/DatabaseCleaner/database_cleaner/pull/650
|
16
|
+
|
17
|
+
== Bugfixes
|
18
|
+
* Fix deprecation warning about `DatabaseCleaner.connections` to recommend a better alternative: https://github.com/DatabaseCleaner/database_cleaner/pull/656
|
19
|
+
|
20
|
+
== 1.8.5 2020-05-04
|
21
|
+
|
22
|
+
=== Bug Fixes
|
23
|
+
* Fix :mongo strategy: https://github.com/DatabaseCleaner/database_cleaner/pull/645
|
24
|
+
|
25
|
+
== 1.8.4 2020-04-02
|
26
|
+
|
2
27
|
=== Bug Fixes
|
28
|
+
* Fix false positive deprecation warnings on Windows: https://github.com/DatabaseCleaner/database_cleaner/pull/633
|
29
|
+
|
30
|
+
== 1.8.3 2020-02-18
|
31
|
+
|
32
|
+
=== Bug Fixes
|
33
|
+
* Fix performance issue of DatabaseCleaner::Base#orm_module: https://github.com/DatabaseCleaner/database_cleaner/pull/625
|
34
|
+
|
35
|
+
== 1.8.2 2020-02-01
|
36
|
+
|
37
|
+
=== Bug Fixes
|
38
|
+
* Fix database_cleaner-ohm autodetected adapter loading: https://github.com/DatabaseCleaner/database_cleaner/pull/619
|
39
|
+
* Fix database_cleaner-mongo_mapper autodetected adapter loading: @botandrose
|
40
|
+
* Fix database_cleaner-mongoid autodetected adapter loading: https://github.com/DatabaseCleaner/database_cleaner/pull/617
|
41
|
+
* Exclude ar_internal_metadata from truncation on Rails 5: https://github.com/DatabaseCleaner/database_cleaner/pull/588
|
42
|
+
|
3
43
|
=== Changes
|
44
|
+
* Deprecate ohm adapter: https://github.com/DatabaseCleaner/database_cleaner/pull/619
|
4
45
|
|
5
46
|
== 1.8.1 2020-01-30
|
6
47
|
|
data/README.markdown
CHANGED
@@ -8,6 +8,8 @@ you're reading the documentation for the `master` branch.
|
|
8
8
|
|
9
9
|
[![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner)
|
10
10
|
[![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner)
|
11
|
+
![Gem Version](https://badge.fury.io/rb/database_cleaner.svg)
|
12
|
+
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=database_cleaner&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=database_cleaner&package-manager=bundler&version-scheme=semver)
|
11
13
|
|
12
14
|
Database Cleaner is a set of gems containing strategies for cleaning your database in Ruby.
|
13
15
|
|
@@ -304,10 +306,10 @@ DatabaseCleaner[:active_record].strategy = :transaction
|
|
304
306
|
DatabaseCleaner[:mongo_mapper].strategy = :truncation
|
305
307
|
|
306
308
|
# How to specify particular connections
|
307
|
-
DatabaseCleaner[:active_record, { :
|
309
|
+
DatabaseCleaner[:active_record, { :db => :two }]
|
308
310
|
|
309
311
|
# You may also pass in the model directly:
|
310
|
-
DatabaseCleaner[:active_record, { :
|
312
|
+
DatabaseCleaner[:active_record, { :db => ModelWithDifferentConnection }]
|
311
313
|
```
|
312
314
|
|
313
315
|
Usage beyond that remains the same with `DatabaseCleaner.start` calling any setup on the different configured connections, and `DatabaseCleaner.clean` executing afterwards.
|
@@ -384,4 +386,4 @@ DatabaseCleaner.url_whitelist = ['postgres://postgres@localhost', 'postgres://fo
|
|
384
386
|
|
385
387
|
## COPYRIGHT
|
386
388
|
|
387
|
-
See [LICENSE] for details.
|
389
|
+
See [LICENSE](LICENSE) for details.
|
data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/truncation.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'active_record/base'
|
2
2
|
require 'database_cleaner/active_record/base'
|
3
3
|
require 'active_record/connection_adapters/abstract_adapter'
|
4
|
+
require 'database_cleaner/deprecation'
|
4
5
|
|
5
6
|
#Load available connection adapters
|
6
7
|
%w(
|
@@ -233,6 +234,13 @@ module DatabaseCleaner::ActiveRecord
|
|
233
234
|
include ::DatabaseCleaner::ActiveRecord::Base
|
234
235
|
include ::DatabaseCleaner::Generic::Truncation
|
235
236
|
|
237
|
+
def initialize(*)
|
238
|
+
super
|
239
|
+
if !@reset_ids.nil?
|
240
|
+
DatabaseCleaner.deprecate "The `:reset_ids` option for the ActiveRecord truncation strategy has no effect, and is deprecated. It will be removed in database_cleaner 2.0 with no replacement."
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
236
244
|
def clean
|
237
245
|
connection = connection_class.connection
|
238
246
|
connection.disable_referential_integrity do
|
@@ -260,7 +268,9 @@ module DatabaseCleaner::ActiveRecord
|
|
260
268
|
|
261
269
|
# overwritten
|
262
270
|
def migration_storage_names
|
263
|
-
[::DatabaseCleaner::ActiveRecord::Base.migration_table_name]
|
271
|
+
result = [::DatabaseCleaner::ActiveRecord::Base.migration_table_name]
|
272
|
+
result << ::ActiveRecord::Base.internal_metadata_table_name if ::ActiveRecord::VERSION::MAJOR >= 5
|
273
|
+
result
|
264
274
|
end
|
265
275
|
|
266
276
|
def cache_tables?
|
@@ -3,6 +3,8 @@ require "database_cleaner"
|
|
3
3
|
require "database_cleaner/couch_potato/base"
|
4
4
|
require "database_cleaner/couch_potato/truncation"
|
5
5
|
|
6
|
+
DatabaseCleaner.deprecate "Due to lack of maintenance, the Couch Potato adapter for DatabaseCleaner is deprecated, and will be removed in v2.0 with no replacement. Contact us if you are interested in resurrecting this adapter!"
|
7
|
+
|
6
8
|
module DatabaseCleaner::CouchPotato
|
7
9
|
def self.default_strategy
|
8
10
|
:truncation
|
@@ -2,3 +2,5 @@ require "database_cleaner/data_mapper/version"
|
|
2
2
|
require "database_cleaner"
|
3
3
|
require "database_cleaner/data_mapper/transaction"
|
4
4
|
require "database_cleaner/data_mapper/truncation"
|
5
|
+
|
6
|
+
DatabaseCleaner.deprecate "Due to lack of maintenance, the DataMapper adapter for DatabaseCleaner is deprecated, and will be removed in v2.0 with no replacement. Contact us if you are interested in resurrecting this adapter!"
|
@@ -1,12 +1,24 @@
|
|
1
1
|
require 'database_cleaner/mongo/base'
|
2
|
+
require 'database_cleaner/generic/base'
|
2
3
|
require 'database_cleaner/generic/truncation'
|
3
4
|
require 'database_cleaner/mongo/truncation_mixin'
|
5
|
+
require 'database_cleaner/deprecation'
|
6
|
+
|
4
7
|
module DatabaseCleaner
|
5
8
|
module Mongo
|
6
9
|
class Truncation
|
10
|
+
include ::DatabaseCleaner::Generic::Base
|
7
11
|
include ::DatabaseCleaner::Generic::Truncation
|
8
12
|
include TruncationMixin
|
9
13
|
include Base
|
14
|
+
|
15
|
+
def initialize(opts={})
|
16
|
+
super
|
17
|
+
if !opts.has_key?(:cache_tables) || opts[:cache_tables]
|
18
|
+
DatabaseCleaner.deprecate "The mongo adapter caches collection names between cleanings. However, this behavior can introduce test-order-dependency issues, because the collections that exist after the first test has executed are saved and used for the remainder of the suite. This means that any collection created during the subsequent tests are not cleaned! This is fixed in database_cleaner-mongo 2.0 by removing this collection caching functionality altogether. To ease the transition into this new behavior, it can be opted into by specifying the `:cache_tables` option to false: `DatabaseCleaner[:mongo].strategy = :deletion, cache_tables: false`. For more information, see https://github.com/DatabaseCleaner/database_cleaner/pull/646"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
10
22
|
private
|
11
23
|
|
12
24
|
def database
|
@@ -14,11 +26,11 @@ module DatabaseCleaner
|
|
14
26
|
end
|
15
27
|
|
16
28
|
def collections_cache
|
17
|
-
|
29
|
+
@collections_cache ||= {}
|
18
30
|
end
|
19
31
|
|
20
32
|
def mongoid_collection_names
|
21
|
-
|
33
|
+
@mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names|
|
22
34
|
ObjectSpace.each_object(Class) do |klass|
|
23
35
|
(names[klass.db.name] << klass.collection_name) if valid_collection_name?(klass)
|
24
36
|
end
|
@@ -26,17 +38,17 @@ module DatabaseCleaner
|
|
26
38
|
end
|
27
39
|
|
28
40
|
def not_caching(db_name, list)
|
29
|
-
|
41
|
+
@not_caching ||= {}
|
30
42
|
|
31
|
-
unless
|
32
|
-
|
43
|
+
unless @not_caching.has_key?(db_name)
|
44
|
+
@not_caching[db_name] = true
|
33
45
|
|
34
46
|
puts "Not caching collection names for db #{db_name}. Missing these from models: #{list}"
|
35
47
|
end
|
36
48
|
end
|
37
49
|
|
38
50
|
def collections
|
39
|
-
return collections_cache[database.name] if collections_cache.has_key?(database.name)
|
51
|
+
return collections_cache[database.name] if collections_cache.has_key?(database.name) && @cache_tables
|
40
52
|
db_collections = database.collections.select { |c| c.name !~ /^system\./ }
|
41
53
|
|
42
54
|
missing_collections = mongoid_collection_names[database.name] - db_collections.map(&:name)
|
@@ -2,3 +2,4 @@ require "database_cleaner/mongo_mapper/version"
|
|
2
2
|
require "database_cleaner"
|
3
3
|
require "database_cleaner/mongo_mapper/truncation"
|
4
4
|
|
5
|
+
DatabaseCleaner.deprecate "Due to lack of maintenance, the MongoMapper adapter for DatabaseCleaner is deprecated, and will be removed in v2.0 with no replacement. Contact us if you are interested in resurrecting this adapter!"
|
@@ -1,16 +1,32 @@
|
|
1
1
|
require 'database_cleaner/mongo_mapper/base'
|
2
2
|
require 'database_cleaner/generic/truncation'
|
3
|
-
require 'database_cleaner/mongo/truncation_mixin'
|
4
3
|
|
5
4
|
module DatabaseCleaner
|
6
5
|
module MongoMapper
|
7
6
|
class Truncation
|
8
7
|
include ::DatabaseCleaner::MongoMapper::Base
|
9
8
|
include ::DatabaseCleaner::Generic::Truncation
|
10
|
-
|
11
|
-
|
9
|
+
|
10
|
+
def clean
|
11
|
+
if @only
|
12
|
+
collections.each { |c| c.send(truncate_method_name) if @only.include?(c.name) }
|
13
|
+
else
|
14
|
+
collections.each { |c| c.send(truncate_method_name) unless @tables_to_exclude.include?(c.name) }
|
15
|
+
end
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
12
19
|
private
|
13
20
|
|
21
|
+
def collections
|
22
|
+
database.collections.select { |c| c.name !~ /^system\./ }
|
23
|
+
end
|
24
|
+
|
25
|
+
def truncate_method_name
|
26
|
+
# This constant only exists in the 2.x series.
|
27
|
+
defined?(::Mongo::VERSION) ? :delete_many : :remove
|
28
|
+
end
|
29
|
+
|
14
30
|
def database
|
15
31
|
::MongoMapper.database
|
16
32
|
end
|
data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module DatabaseCleaner
|
2
|
+
module Mongoid
|
3
|
+
module Mongo1TruncationMixin
|
4
|
+
def clean
|
5
|
+
if @only
|
6
|
+
collections.each { |c| c.send(truncate_method_name) if @only.include?(c.name) }
|
7
|
+
else
|
8
|
+
collections.each { |c| c.send(truncate_method_name) unless @tables_to_exclude.include?(c.name) }
|
9
|
+
end
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def collections
|
16
|
+
database.collections.select { |c| c.name !~ /^system\./ }
|
17
|
+
end
|
18
|
+
|
19
|
+
def truncate_method_name
|
20
|
+
# This constant only exists in the 2.x series.
|
21
|
+
defined?(::Mongo::VERSION) ? :delete_many : :remove
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module DatabaseCleaner
|
2
|
-
module
|
3
|
-
module
|
4
|
-
|
2
|
+
module Mongoid
|
3
|
+
module Mongo2TruncationMixin
|
5
4
|
def clean
|
6
5
|
if @only
|
7
6
|
collections.each { |c| database[c].find.delete_many if @only.include?(c) }
|
@@ -33,7 +32,7 @@ module DatabaseCleaner
|
|
33
32
|
# name
|
34
33
|
# end
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
38
|
+
|
data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'database_cleaner/generic/base'
|
2
|
+
require 'database_cleaner/generic/truncation'
|
3
|
+
|
4
|
+
module DatabaseCleaner
|
5
|
+
module Mongoid
|
6
|
+
module MongoidTruncationMixin
|
7
|
+
include ::DatabaseCleaner::Generic::Base
|
8
|
+
include ::DatabaseCleaner::Generic::Truncation
|
9
|
+
|
10
|
+
def db=(desired_db)
|
11
|
+
@db = desired_db
|
12
|
+
end
|
13
|
+
|
14
|
+
def db
|
15
|
+
@db ||= :default
|
16
|
+
end
|
17
|
+
|
18
|
+
def host_port=(desired_host)
|
19
|
+
@host = desired_host
|
20
|
+
end
|
21
|
+
|
22
|
+
def host
|
23
|
+
@host ||= '127.0.0.1:27017'
|
24
|
+
end
|
25
|
+
|
26
|
+
def db_version
|
27
|
+
@db_version ||= session.command('buildinfo' => 1)['version']
|
28
|
+
end
|
29
|
+
|
30
|
+
def clean
|
31
|
+
if @only
|
32
|
+
collections.each { |c| session[c].find.remove_all if @only.include?(c) }
|
33
|
+
else
|
34
|
+
collections.each { |c| session[c].find.remove_all unless @tables_to_exclude.include?(c) }
|
35
|
+
end
|
36
|
+
wait_for_removals_to_finish
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def collections
|
43
|
+
if db != :default
|
44
|
+
session.use(db)
|
45
|
+
end
|
46
|
+
|
47
|
+
if db_version.split('.').first.to_i >= 3
|
48
|
+
session.command(listCollections: 1, filter: { 'name' => { '$not' => /.?system\.|\$/ } })['cursor']['firstBatch'].map do |collection|
|
49
|
+
collection['name']
|
50
|
+
end
|
51
|
+
else
|
52
|
+
session['system.namespaces'].find(name: { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
|
53
|
+
_, name = collection['name'].split('.', 2)
|
54
|
+
name
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def wait_for_removals_to_finish
|
60
|
+
session.command(getlasterror: 1)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'database_cleaner/mongoid/base'
|
2
2
|
require 'database_cleaner/generic/truncation'
|
3
|
-
require 'database_cleaner/
|
4
|
-
require 'database_cleaner/
|
5
|
-
require 'database_cleaner/
|
3
|
+
require 'database_cleaner/mongoid/mongo1_truncation_mixin'
|
4
|
+
require 'database_cleaner/mongoid/mongo2_truncation_mixin'
|
5
|
+
require 'database_cleaner/mongoid/mongoid_truncation_mixin'
|
6
6
|
require 'mongoid/version'
|
7
7
|
|
8
8
|
module DatabaseCleaner
|
@@ -13,7 +13,7 @@ module DatabaseCleaner
|
|
13
13
|
|
14
14
|
if ::Mongoid::VERSION < '3'
|
15
15
|
|
16
|
-
include ::DatabaseCleaner::
|
16
|
+
include ::DatabaseCleaner::Mongoid::Mongo1TruncationMixin
|
17
17
|
|
18
18
|
private
|
19
19
|
|
@@ -23,7 +23,7 @@ module DatabaseCleaner
|
|
23
23
|
|
24
24
|
elsif ::Mongoid::VERSION < '5'
|
25
25
|
|
26
|
-
include ::DatabaseCleaner::
|
26
|
+
include ::DatabaseCleaner::Mongoid::MongoidTruncationMixin
|
27
27
|
|
28
28
|
private
|
29
29
|
|
@@ -41,7 +41,7 @@ module DatabaseCleaner
|
|
41
41
|
|
42
42
|
else
|
43
43
|
|
44
|
-
include ::DatabaseCleaner::
|
44
|
+
include ::DatabaseCleaner::Mongoid::Mongo2TruncationMixin
|
45
45
|
|
46
46
|
end
|
47
47
|
end
|
@@ -2,6 +2,8 @@ require "database_cleaner/moped/version"
|
|
2
2
|
require "database_cleaner"
|
3
3
|
require "database_cleaner/moped/truncation"
|
4
4
|
|
5
|
+
DatabaseCleaner.deprecate "Due to lack of maintenance, the Moped adapter for DatabaseCleaner is deprecated, and will be removed in v2.0 with no replacement. Contact us if you are interested in resurrecting this adapter!"
|
6
|
+
|
5
7
|
module DatabaseCleaner::Moped
|
6
8
|
def self.default_strategy
|
7
9
|
:truncation
|
@@ -4,3 +4,4 @@ require "database_cleaner/neo4j/transaction"
|
|
4
4
|
require "database_cleaner/neo4j/truncation"
|
5
5
|
require "database_cleaner/neo4j/deletion"
|
6
6
|
|
7
|
+
DatabaseCleaner.deprecate "Due to lack of maintenance, the Neo4j adapter for DatabaseCleaner is deprecated, and will be removed in v2.0 with no replacement. Contact us if you are interested in resurrecting this adapter!"
|
@@ -2,6 +2,8 @@ require "database_cleaner/ohm/version"
|
|
2
2
|
require "database_cleaner"
|
3
3
|
require "database_cleaner/ohm/truncation"
|
4
4
|
|
5
|
+
DatabaseCleaner.deprecate "The Ohm adapter for DatabaseCleaner is deprecated, and will be removed in v2.0. Please use the Redis adapter instead."
|
6
|
+
|
5
7
|
module DatabaseCleaner::Ohm
|
6
8
|
def self.default_strategy
|
7
9
|
:truncation
|
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
begin # when database_cleaner-ohm is loaded as a gem
|
2
|
+
require 'database_cleaner/redis/truncation'
|
3
|
+
rescue LoadError # when database_cleaner is loaded as a gem
|
4
|
+
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../../../../adapters/database_cleaner-redis/lib")
|
5
|
+
require 'database_cleaner/redis/truncation'
|
6
|
+
end
|
2
7
|
|
3
8
|
module DatabaseCleaner
|
4
9
|
module Ohm
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'database_cleaner/generic/base'
|
2
|
+
require 'database_cleaner/deprecation'
|
2
3
|
|
3
4
|
module DatabaseCleaner
|
4
5
|
module Redis
|
5
6
|
def self.available_strategies
|
6
|
-
%w{truncation}
|
7
|
+
%w{truncation deletion}
|
7
8
|
end
|
8
9
|
|
9
10
|
def self.default_strategy
|
@@ -21,7 +22,10 @@ module DatabaseCleaner
|
|
21
22
|
@db ||= :default
|
22
23
|
end
|
23
24
|
|
24
|
-
|
25
|
+
def url
|
26
|
+
DatabaseCleaner.deprecate "The redis deletion strategy's #url method is deprecated. It will be removed in database_cleaner-redis 2.0 in favor of #db."
|
27
|
+
db
|
28
|
+
end
|
25
29
|
|
26
30
|
private
|
27
31
|
|
@@ -32,7 +36,7 @@ module DatabaseCleaner
|
|
32
36
|
elsif db.is_a?(::Redis) # pass directly the connection
|
33
37
|
db
|
34
38
|
else
|
35
|
-
::Redis.new(:url =>
|
39
|
+
::Redis.new(:url => db)
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
@@ -15,7 +15,13 @@ module DatabaseCleaner
|
|
15
15
|
def initialize(desired_orm = nil, opts = {})
|
16
16
|
@orm_autodetector = ORMAutodetector.new
|
17
17
|
self.orm = desired_orm
|
18
|
-
|
18
|
+
if opts.has_key?(:model)
|
19
|
+
DatabaseCleaner.deprecate "Using the `:model` key in `DatabaseCleaner[:orm, model: ...]` is deprecated, and will be removed in database_cleaner 2.0. Please use the new `:db` key, instead, which has identical behavior: `DatabaseCleaner[:orm, db: ...]`."
|
20
|
+
end
|
21
|
+
if opts.has_key?(:connection)
|
22
|
+
DatabaseCleaner.deprecate "Using the `:connection` key in `DatabaseCleaner[:orm, connection: ...]` is deprecated, and will be removed in database_cleaner 2.0. Please use the new `:db` key, instead, which has identical behavior: `DatabaseCleaner[:orm, db: ...]`."
|
23
|
+
end
|
24
|
+
self.db = opts[:db] || opts[:connection] || opts[:model] if opts.has_key?(:db) || opts.has_key?(:connection) || opts.has_key?(:model)
|
19
25
|
self.strategy = orm_module && orm_module.default_strategy
|
20
26
|
Safeguard.new.run
|
21
27
|
end
|
@@ -30,6 +36,13 @@ module DatabaseCleaner
|
|
30
36
|
|
31
37
|
def strategy=(args)
|
32
38
|
strategy, *strategy_args = args
|
39
|
+
|
40
|
+
if DatabaseCleaner.called_externally?(__FILE__, caller) \
|
41
|
+
&& [:redis, :mongo, :mongoid].include?(orm) \
|
42
|
+
&& strategy == :truncation
|
43
|
+
DatabaseCleaner.deprecate "The #{orm} adapter's :truncation strategy will be renamed to :deletion in database_cleaner-#{orm} 2.0. Please specify the :deletion adapter to resolve this deprecation notice."
|
44
|
+
end
|
45
|
+
|
33
46
|
@strategy = if strategy.is_a?(Symbol)
|
34
47
|
create_strategy(*args)
|
35
48
|
elsif strategy_args.empty?
|
@@ -48,6 +61,9 @@ module DatabaseCleaner
|
|
48
61
|
attr_reader :orm
|
49
62
|
|
50
63
|
def orm=(desired_orm)
|
64
|
+
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
65
|
+
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[:orm].orm=` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
66
|
+
end
|
51
67
|
@orm = (desired_orm || :autodetect).to_sym
|
52
68
|
@orm = @orm_autodetector.orm if @orm == :autodetect
|
53
69
|
end
|
@@ -87,14 +103,14 @@ module DatabaseCleaner
|
|
87
103
|
# TODO privatize the following methods in 2.0
|
88
104
|
|
89
105
|
def strategy_db=(desired_db)
|
90
|
-
if called_externally?(caller)
|
106
|
+
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
91
107
|
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].strategy_db=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].db=` instead."
|
92
108
|
end
|
93
109
|
set_strategy_db(strategy, desired_db)
|
94
110
|
end
|
95
111
|
|
96
112
|
def set_strategy_db(strategy, desired_db)
|
97
|
-
if called_externally?(caller)
|
113
|
+
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
98
114
|
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].set_strategy_db=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].db=` instead."
|
99
115
|
end
|
100
116
|
if strategy.respond_to? :db=
|
@@ -105,7 +121,7 @@ module DatabaseCleaner
|
|
105
121
|
end
|
106
122
|
|
107
123
|
def create_strategy(*args)
|
108
|
-
if called_externally?(caller)
|
124
|
+
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
109
125
|
DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].create_strategy` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].strategy=` instead."
|
110
126
|
end
|
111
127
|
strategy, *strategy_args = args
|
@@ -116,15 +132,23 @@ module DatabaseCleaner
|
|
116
132
|
|
117
133
|
def orm_module
|
118
134
|
return unless [:active_record, :data_mapper, :mongo, :mongoid, :mongo_mapper, :moped, :couch_potato, :sequel, :ohm, :redis, :neo4j].include?(orm)
|
135
|
+
load_adapter(orm) if !adapter_loaded?(orm)
|
136
|
+
orm_module_name = ORMAutodetector::ORMS[orm]
|
137
|
+
DatabaseCleaner.const_get(orm_module_name, false)
|
138
|
+
end
|
139
|
+
|
140
|
+
def adapter_loaded? orm
|
141
|
+
$LOADED_FEATURES.grep(%r{/lib/database_cleaner/#{orm}\.rb$}).any?
|
142
|
+
end
|
143
|
+
|
144
|
+
def load_adapter orm
|
119
145
|
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../adapters/database_cleaner-#{orm}/lib")
|
120
146
|
require "database_cleaner/#{orm}"
|
121
|
-
orm_module_name = ORMAutodetector::ORMS[orm]
|
122
|
-
DatabaseCleaner.const_get(orm_module_name)
|
123
147
|
end
|
124
148
|
|
125
149
|
def orm_strategy(strategy)
|
126
150
|
strategy_module_name = strategy.to_s.capitalize
|
127
|
-
orm_module.const_get(strategy_module_name)
|
151
|
+
orm_module.const_get(strategy_module_name, false)
|
128
152
|
rescue NameError
|
129
153
|
if orm != :active_record
|
130
154
|
DatabaseCleaner.deprecate <<-TEXT
|
@@ -141,9 +165,5 @@ module DatabaseCleaner
|
|
141
165
|
rescue LoadError
|
142
166
|
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}"
|
143
167
|
end
|
144
|
-
|
145
|
-
def called_externally?(caller)
|
146
|
-
__FILE__ != caller.first.split(":").first
|
147
|
-
end
|
148
168
|
end
|
149
169
|
end
|
@@ -21,6 +21,7 @@ module DatabaseCleaner
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def orm=(orm)
|
24
|
+
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.orm=` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
24
25
|
add_cleaner(:autodetect) if none?
|
25
26
|
values.each { |cleaner| cleaner.orm = orm }
|
26
27
|
remove_duplicates
|
@@ -109,8 +110,8 @@ module DatabaseCleaner
|
|
109
110
|
end
|
110
111
|
|
111
112
|
def connections
|
112
|
-
if called_externally?(caller)
|
113
|
-
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.connections` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.cleaners`, instead."
|
113
|
+
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
114
|
+
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.connections` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.cleaners.values`, instead."
|
114
115
|
end
|
115
116
|
add_cleaner(:autodetect) if @cleaners.none?
|
116
117
|
@cleaners.values
|
@@ -119,23 +120,17 @@ module DatabaseCleaner
|
|
119
120
|
# TODO privatize the following methods in 2.0
|
120
121
|
|
121
122
|
def add_cleaner(orm, opts = {})
|
122
|
-
if called_externally?(caller)
|
123
|
+
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
123
124
|
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.add_cleaner` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.[]`, instead."
|
124
125
|
end
|
125
126
|
@cleaners.add_cleaner(orm, opts = {})
|
126
127
|
end
|
127
128
|
|
128
129
|
def remove_duplicates
|
129
|
-
if called_externally?(caller)
|
130
|
+
if DatabaseCleaner.called_externally?(__FILE__, caller)
|
130
131
|
DatabaseCleaner.deprecate "Calling `DatabaseCleaner.remove_duplicates` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
|
131
132
|
end
|
132
133
|
@cleaners.remove_duplicates
|
133
134
|
end
|
134
|
-
|
135
|
-
private
|
136
|
-
|
137
|
-
def called_externally?(caller)
|
138
|
-
__FILE__ != caller.first.split(":").first
|
139
|
-
end
|
140
135
|
end
|
141
136
|
end
|
@@ -6,6 +6,11 @@ module DatabaseCleaner
|
|
6
6
|
end
|
7
7
|
module_function :deprecate
|
8
8
|
|
9
|
+
def called_externally?(file, caller)
|
10
|
+
file != caller.first[/^(.+\.rb):\d+/, 1]
|
11
|
+
end
|
12
|
+
module_function :called_externally?
|
13
|
+
|
9
14
|
class Deprecator
|
10
15
|
def initialize
|
11
16
|
@methods_already_warned = {}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.99.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Mabey
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -442,6 +442,7 @@ files:
|
|
442
442
|
- adapters/database_cleaner-mongo/lib/database_cleaner-mongo.rb
|
443
443
|
- adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb
|
444
444
|
- adapters/database_cleaner-mongo/lib/database_cleaner/mongo/base.rb
|
445
|
+
- adapters/database_cleaner-mongo/lib/database_cleaner/mongo/deletion.rb
|
445
446
|
- adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation.rb
|
446
447
|
- adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation_mixin.rb
|
447
448
|
- adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb
|
@@ -451,9 +452,12 @@ files:
|
|
451
452
|
- adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb
|
452
453
|
- adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb
|
453
454
|
- adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb
|
454
|
-
- adapters/database_cleaner-mongoid/lib/database_cleaner/mongo2/truncation_mixin.rb
|
455
455
|
- adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb
|
456
456
|
- adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/base.rb
|
457
|
+
- adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/deletion.rb
|
458
|
+
- adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb
|
459
|
+
- adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb
|
460
|
+
- adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb
|
457
461
|
- adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/truncation.rb
|
458
462
|
- adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb
|
459
463
|
- adapters/database_cleaner-moped/lib/database_cleaner-moped.rb
|
@@ -476,6 +480,7 @@ files:
|
|
476
480
|
- adapters/database_cleaner-redis/lib/database_cleaner-redis.rb
|
477
481
|
- adapters/database_cleaner-redis/lib/database_cleaner/redis.rb
|
478
482
|
- adapters/database_cleaner-redis/lib/database_cleaner/redis/base.rb
|
483
|
+
- adapters/database_cleaner-redis/lib/database_cleaner/redis/deletion.rb
|
479
484
|
- adapters/database_cleaner-redis/lib/database_cleaner/redis/truncation.rb
|
480
485
|
- adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb
|
481
486
|
- adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb
|
@@ -516,11 +521,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
516
521
|
version: 1.9.3
|
517
522
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
518
523
|
requirements:
|
519
|
-
- - "
|
524
|
+
- - ">"
|
520
525
|
- !ruby/object:Gem::Version
|
521
|
-
version:
|
526
|
+
version: 1.3.1
|
522
527
|
requirements: []
|
523
|
-
rubygems_version: 3.0.
|
528
|
+
rubygems_version: 3.0.8
|
524
529
|
signing_key:
|
525
530
|
specification_version: 4
|
526
531
|
summary: Strategies for cleaning databases. Can be used to ensure a clean slate for
|