database_cleaner-mongo 1.99.0.beta → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +7 -2
- data/Gemfile +8 -3
- data/README.md +4 -31
- data/database_cleaner-mongo.gemspec +7 -10
- data/lib/database_cleaner/mongo.rb +2 -8
- data/lib/database_cleaner/mongo/deletion.rb +31 -2
- data/lib/database_cleaner/mongo/version.rb +1 -1
- metadata +22 -25
- data/Gemfile.lock +0 -46
- data/lib/database_cleaner/mongo/base.rb +0 -16
- data/lib/database_cleaner/mongo/truncation.rb +0 -74
- data/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '090438e884857bdd0920e5e97faee912ab745c5f8e5125081bcf8c3f8e4ea858'
|
4
|
+
data.tar.gz: a5034e10651fdb11bcebd852fe4e08104840a6dc98d969ff21ec55c4bff05ac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51c1d0999bd74d9cb11a643fcc5b301eef51ff94b67b9992bfcc3d132c4149b08c7cc17630ede9f39abdb292252d8c549d229b8503a4f52b94d13a7576fe552c
|
7
|
+
data.tar.gz: 27a70e6091addc71d449cf7712d565258cc451b6e22f1a1c9c6095aa756897f19201e3917c3ed9dec6ce37758e4a820818b135cd4ed4749348ec32c69c240abb
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
|
5
3
|
# Specify your gem's dependencies in database_cleaner-mongo.gemspec
|
6
4
|
gemspec
|
7
5
|
|
8
|
-
gem "database_cleaner",
|
6
|
+
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
|
7
|
+
|
8
|
+
gem "byebug"
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem "simplecov", require: false
|
12
|
+
gem "codecov", require: false
|
13
|
+
end
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner-mongo.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner-mongo)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner-mongo/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner-mongo)
|
5
|
+
[![codecov](https://codecov.io/gh/DatabaseCleaner/database_cleaner-mongo/branch/master/graph/badge.svg)](https://codecov.io/gh/DatabaseCleaner/database_cleaner-mongo)
|
5
6
|
|
6
7
|
Clean your Mongo databases with Database Cleaner.
|
7
8
|
|
@@ -18,40 +19,12 @@ end
|
|
18
19
|
|
19
20
|
## Supported Strategies
|
20
21
|
|
21
|
-
|
22
|
-
<tbody>
|
23
|
-
<tr>
|
24
|
-
<th>Truncation</th>
|
25
|
-
<th>Transaction</th>
|
26
|
-
<th>Deletion</th>
|
27
|
-
</tr>
|
28
|
-
<tr>
|
29
|
-
<td> <b>Yes</b></td>
|
30
|
-
<td> No</td>
|
31
|
-
<td> No</td>
|
32
|
-
</tr>
|
33
|
-
</tbody>
|
34
|
-
</table>
|
35
|
-
|
36
|
-
(Default strategy is denoted in bold)
|
22
|
+
The mongo adapter only has one strategy: the deletion strategy.
|
37
23
|
|
38
24
|
## Configuration options
|
39
25
|
|
40
|
-
|
41
|
-
<tbody>
|
42
|
-
<tr>
|
43
|
-
<th>ORM</th>
|
44
|
-
<th>How to access</th>
|
45
|
-
<th>Notes</th>
|
46
|
-
</tr>
|
47
|
-
<tr>
|
48
|
-
<td> Mongo</td>
|
49
|
-
<td> <code>DatabaseCleaner[:mongo]</code></td>
|
50
|
-
<td> </td>
|
51
|
-
</tr>
|
52
|
-
</tbody>
|
53
|
-
</table>
|
26
|
+
The deletion strategy has no options.
|
54
27
|
|
55
28
|
## COPYRIGHT
|
56
29
|
|
57
|
-
See [LICENSE] for details.
|
30
|
+
See [LICENSE](LICENSE) for details.
|
@@ -1,12 +1,9 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "database_cleaner/mongo/version"
|
1
|
+
require_relative "./lib/database_cleaner/mongo/version"
|
5
2
|
|
6
3
|
Gem::Specification.new do |spec|
|
7
4
|
spec.name = "database_cleaner-mongo"
|
8
5
|
spec.version = DatabaseCleaner::Mongo::VERSION
|
9
|
-
spec.authors = ["Ernesto Tagwerker"]
|
6
|
+
spec.authors = ["Ernesto Tagwerker", "Micah Geisel"]
|
10
7
|
spec.email = ["ernesto@ombulabs.com"]
|
11
8
|
|
12
9
|
spec.summary = "Strategies for cleaning databases using Mongo. Can be used to ensure a clean state for testing."
|
@@ -21,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
21
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
19
|
spec.require_paths = ["lib"]
|
23
20
|
|
24
|
-
spec.add_dependency "database_cleaner", "~>
|
25
|
-
spec.add_dependency "mongo"
|
21
|
+
spec.add_dependency "database_cleaner-core", "~>2.0.0.beta2"
|
22
|
+
spec.add_dependency "mongo", "~>2.0"
|
26
23
|
|
27
|
-
spec.add_development_dependency "bundler"
|
28
|
-
spec.add_development_dependency "rake"
|
29
|
-
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
30
27
|
end
|
@@ -1,11 +1,5 @@
|
|
1
1
|
require 'database_cleaner/mongo/version'
|
2
|
-
require 'database_cleaner'
|
3
|
-
require 'database_cleaner/mongo/truncation'
|
2
|
+
require 'database_cleaner/core'
|
4
3
|
require 'database_cleaner/mongo/deletion'
|
5
4
|
|
6
|
-
|
7
|
-
def self.default_strategy
|
8
|
-
:truncation
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
5
|
+
DatabaseCleaner[:mongo].strategy = :deletion
|
@@ -1,8 +1,37 @@
|
|
1
|
-
require 'database_cleaner/
|
1
|
+
require 'database_cleaner/strategy'
|
2
|
+
require 'database_cleaner/deprecation'
|
3
|
+
require 'mongo'
|
2
4
|
|
3
5
|
module DatabaseCleaner
|
4
6
|
module Mongo
|
5
|
-
class Deletion <
|
7
|
+
class Deletion < Strategy
|
8
|
+
def initialize only: [], except: [], cache_tables: nil
|
9
|
+
@only = only
|
10
|
+
@except = except
|
11
|
+
if !cache_tables.nil?
|
12
|
+
DatabaseCleaner.deprecate "The mongo adapter's :cache_tables option has no effect, and will be removed in database_cleaner-mongo 3.0."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def db
|
17
|
+
@db || raise("You have not specified a database. (see Mongo::Database)")
|
18
|
+
end
|
19
|
+
|
20
|
+
def clean
|
21
|
+
collections_to_delete.each(&:delete_many)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def collections_to_delete
|
27
|
+
collections.select do |c|
|
28
|
+
(@only.none? || @only.include?(c.name)) && !@except.include?(c.name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def collections
|
33
|
+
db.collections.select { |c| c.name !~ /^system\./ }
|
34
|
+
end
|
6
35
|
end
|
7
36
|
end
|
8
37
|
end
|
metadata
CHANGED
@@ -1,85 +1,86 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_cleaner-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernesto Tagwerker
|
8
|
+
- Micah Geisel
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
12
|
date: 2020-05-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: database_cleaner
|
15
|
+
name: database_cleaner-core
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
+
version: 2.0.0.beta2
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
+
version: 2.0.0.beta2
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: mongo
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- - "
|
32
|
+
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
+
version: '2.0'
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- - "
|
39
|
+
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
+
version: '2.0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: bundler
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- - "
|
46
|
+
- - ">="
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
+
version: '0'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- - "
|
53
|
+
- - ">="
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
+
version: '0'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: rake
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- - "
|
60
|
+
- - ">="
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
+
version: '0'
|
62
63
|
type: :development
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- - "
|
67
|
+
- - ">="
|
67
68
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
+
version: '0'
|
69
70
|
- !ruby/object:Gem::Dependency
|
70
71
|
name: rspec
|
71
72
|
requirement: !ruby/object:Gem::Requirement
|
72
73
|
requirements:
|
73
|
-
- - "
|
74
|
+
- - ">="
|
74
75
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
76
|
+
version: '0'
|
76
77
|
type: :development
|
77
78
|
prerelease: false
|
78
79
|
version_requirements: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
|
-
- - "
|
81
|
+
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
83
|
+
version: '0'
|
83
84
|
description: Strategies for cleaning databases using Mongo. Can be used to ensure
|
84
85
|
a clean state for testing.
|
85
86
|
email:
|
@@ -92,7 +93,6 @@ files:
|
|
92
93
|
- ".rspec"
|
93
94
|
- ".travis.yml"
|
94
95
|
- Gemfile
|
95
|
-
- Gemfile.lock
|
96
96
|
- LICENSE.txt
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
@@ -101,10 +101,7 @@ files:
|
|
101
101
|
- database_cleaner-mongo.gemspec
|
102
102
|
- lib/database_cleaner-mongo.rb
|
103
103
|
- lib/database_cleaner/mongo.rb
|
104
|
-
- lib/database_cleaner/mongo/base.rb
|
105
104
|
- lib/database_cleaner/mongo/deletion.rb
|
106
|
-
- lib/database_cleaner/mongo/truncation.rb
|
107
|
-
- lib/database_cleaner/mongo/truncation_mixin.rb
|
108
105
|
- lib/database_cleaner/mongo/version.rb
|
109
106
|
homepage: https://github.com/DatabaseCleaner/database_cleaner-mongo
|
110
107
|
licenses:
|
@@ -125,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
122
|
- !ruby/object:Gem::Version
|
126
123
|
version: 1.3.1
|
127
124
|
requirements: []
|
128
|
-
rubygems_version: 3.0.
|
125
|
+
rubygems_version: 3.0.3
|
129
126
|
signing_key:
|
130
127
|
specification_version: 4
|
131
128
|
summary: Strategies for cleaning databases using Mongo. Can be used to ensure a clean
|
data/Gemfile.lock
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ../..
|
3
|
-
specs:
|
4
|
-
database_cleaner (1.99.0.beta)
|
5
|
-
|
6
|
-
PATH
|
7
|
-
remote: .
|
8
|
-
specs:
|
9
|
-
database_cleaner-mongo (1.99.0.beta)
|
10
|
-
database_cleaner (~> 1.99.0.beta)
|
11
|
-
mongo
|
12
|
-
|
13
|
-
GEM
|
14
|
-
remote: https://rubygems.org/
|
15
|
-
specs:
|
16
|
-
bson (1.12.5)
|
17
|
-
diff-lcs (1.3)
|
18
|
-
mongo (1.12.5)
|
19
|
-
bson (= 1.12.5)
|
20
|
-
rake (10.4.2)
|
21
|
-
rspec (3.7.0)
|
22
|
-
rspec-core (~> 3.7.0)
|
23
|
-
rspec-expectations (~> 3.7.0)
|
24
|
-
rspec-mocks (~> 3.7.0)
|
25
|
-
rspec-core (3.7.1)
|
26
|
-
rspec-support (~> 3.7.0)
|
27
|
-
rspec-expectations (3.7.0)
|
28
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
-
rspec-support (~> 3.7.0)
|
30
|
-
rspec-mocks (3.7.0)
|
31
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
-
rspec-support (~> 3.7.0)
|
33
|
-
rspec-support (3.7.1)
|
34
|
-
|
35
|
-
PLATFORMS
|
36
|
-
ruby
|
37
|
-
|
38
|
-
DEPENDENCIES
|
39
|
-
bundler (~> 1.16)
|
40
|
-
database_cleaner!
|
41
|
-
database_cleaner-mongo!
|
42
|
-
rake (~> 10.0)
|
43
|
-
rspec (~> 3.0)
|
44
|
-
|
45
|
-
BUNDLED WITH
|
46
|
-
1.17.3
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module DatabaseCleaner
|
2
|
-
module Mongo
|
3
|
-
def self.available_strategies
|
4
|
-
%w[truncation deletion]
|
5
|
-
end
|
6
|
-
module Base
|
7
|
-
def db=(desired_db)
|
8
|
-
@db = desired_db
|
9
|
-
end
|
10
|
-
|
11
|
-
def db
|
12
|
-
@db || raise("You have not specified a database. (see Mongo::Database)")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'database_cleaner/mongo/base'
|
2
|
-
require 'database_cleaner/generic/base'
|
3
|
-
require 'database_cleaner/generic/truncation'
|
4
|
-
require 'database_cleaner/mongo/truncation_mixin'
|
5
|
-
require 'database_cleaner/deprecation'
|
6
|
-
|
7
|
-
module DatabaseCleaner
|
8
|
-
module Mongo
|
9
|
-
class Truncation
|
10
|
-
include ::DatabaseCleaner::Generic::Base
|
11
|
-
include ::DatabaseCleaner::Generic::Truncation
|
12
|
-
include TruncationMixin
|
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
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def database
|
25
|
-
db
|
26
|
-
end
|
27
|
-
|
28
|
-
def collections_cache
|
29
|
-
@collections_cache ||= {}
|
30
|
-
end
|
31
|
-
|
32
|
-
def mongoid_collection_names
|
33
|
-
@mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names|
|
34
|
-
ObjectSpace.each_object(Class) do |klass|
|
35
|
-
(names[klass.db.name] << klass.collection_name) if valid_collection_name?(klass)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def not_caching(db_name, list)
|
41
|
-
@not_caching ||= {}
|
42
|
-
|
43
|
-
unless @not_caching.has_key?(db_name)
|
44
|
-
@not_caching[db_name] = true
|
45
|
-
|
46
|
-
puts "Not caching collection names for db #{db_name}. Missing these from models: #{list}"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def collections
|
51
|
-
return collections_cache[database.name] if collections_cache.has_key?(database.name) && @cache_tables
|
52
|
-
db_collections = database.collections.select { |c| c.name !~ /^system\./ }
|
53
|
-
|
54
|
-
missing_collections = mongoid_collection_names[database.name] - db_collections.map(&:name)
|
55
|
-
|
56
|
-
if missing_collections.empty?
|
57
|
-
collections_cache[database.name] = db_collections
|
58
|
-
else
|
59
|
-
not_caching(database.name, missing_collections)
|
60
|
-
end
|
61
|
-
|
62
|
-
db_collections
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def valid_collection_name?(klass)
|
68
|
-
klass.ancestors.map(&:to_s).include?('Mongoid::Document') &&
|
69
|
-
!klass.embedded &&
|
70
|
-
!klass.collection_name.empty?
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module DatabaseCleaner
|
2
|
-
module Mongo
|
3
|
-
module TruncationMixin
|
4
|
-
|
5
|
-
def clean
|
6
|
-
if @only
|
7
|
-
collections.each { |c| c.send(truncate_method_name) if @only.include?(c.name) }
|
8
|
-
else
|
9
|
-
collections.each { |c| c.send(truncate_method_name) unless @tables_to_exclude.include?(c.name) }
|
10
|
-
end
|
11
|
-
true
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def collections
|
17
|
-
database.collections.select { |c| c.name !~ /^system\./ }
|
18
|
-
end
|
19
|
-
|
20
|
-
def truncate_method_name
|
21
|
-
# This constant only exists in the 2.x series.
|
22
|
-
defined?(::Mongo::VERSION) ? :delete_many : :remove
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|