database_cleaner-mongo 1.8.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e46b0416a90d33ebdf98e4ecafa265caf7bd363c17af1244058200e064cd9a8
4
- data.tar.gz: a9366e34039f290372e2bd406c2702ad61c68eb1cd3929f023a4b63b0f7ec6ae
3
+ metadata.gz: 50993a8f7a76e7ef96b633e916494da06912364cda5becba282eef381bb7d4f2
4
+ data.tar.gz: 4e3e3b23544c3518c64a3609f71a486601314554e9c023d1149fe2275582b800
5
5
  SHA512:
6
- metadata.gz: e88b84c89b7452ff6c65c69bafe048603fc4e0e20eb5644dccf1010e8cfa8c6738d5b61c8f39d720a3baa4cdff9376fc90ace4ed6d23a92b6e14396979cd2168
7
- data.tar.gz: 44cade244dbc9a4f30e6b17bbfe3d308e249a19b5f800995a001bd5d1864997ac61c07347931953a10c3be7446a2d1e8a42ecbd34a00f69face4670ea818556d
6
+ metadata.gz: e4b3372b4c140cc427966a10f5b70c8568104887f2ceeadd2abfb647a1f970bf0f8e234c2ecb8a8d3fc8ee279c27e5c0ee78db987234ba3213ce80b19a5031e9
7
+ data.tar.gz: acf580102d156bcea5b16c27f44b11026fe4708d97f0d7839f34863870ed99e84673ed1b91fb9d719d3d42128f1bf0040a9a8995588eccd8d04005b4364fca28
data/.gitignore CHANGED
@@ -6,6 +6,9 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /.byebug_history
10
+ /.ruby-version
11
+ /Gemfile.lock
9
12
 
10
13
  # rspec failure tracking
11
14
  .rspec_status
@@ -1,5 +1,9 @@
1
- sudo: false
2
1
  language: ruby
2
+ services:
3
+ - mongodb
3
4
  rvm:
4
- - 2.2.9
5
- before_install: gem install bundler -v 1.17.2
5
+ - 2.5
6
+ - 2.6
7
+ - 2.7
8
+ before_script:
9
+ - bin/setup
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", path: "../.."
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
- <table>
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
- <table>
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", "~> 1.8.0"
25
- spec.add_dependency "mongo"
21
+ spec.add_dependency "database_cleaner-core", "~>2.0.0"
22
+ spec.add_dependency "mongo", "~>2.0"
26
23
 
27
- spec.add_development_dependency "bundler", "~> 1.16"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
30
27
  end
@@ -1,10 +1,5 @@
1
1
  require 'database_cleaner/mongo/version'
2
- require 'database_cleaner'
3
- require 'database_cleaner/mongo/truncation'
4
-
5
- module DatabaseCleaner::Mongo
6
- def self.default_strategy
7
- :truncation
8
- end
9
- end
2
+ require 'database_cleaner/core'
3
+ require 'database_cleaner/mongo/deletion'
10
4
 
5
+ DatabaseCleaner[:mongo].strategy = :deletion
@@ -0,0 +1,37 @@
1
+ require 'database_cleaner/strategy'
2
+ require 'database_cleaner/deprecation'
3
+ require 'mongo'
4
+
5
+ module DatabaseCleaner
6
+ module Mongo
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
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  module DatabaseCleaner
2
2
  module Mongo
3
- VERSION = "1.8.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  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: 1.8.0
4
+ version: 2.0.0
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
- date: 2020-01-30 00:00:00.000000000 Z
12
+ date: 2021-01-31 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: 1.8.0
20
+ version: 2.0.0
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: 1.8.0
27
+ version: 2.0.0
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: '1.16'
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: '1.16'
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: '10.0'
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: '10.0'
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: '3.0'
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: '3.0'
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,9 +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
- - lib/database_cleaner/mongo/truncation.rb
106
- - lib/database_cleaner/mongo/truncation_mixin.rb
104
+ - lib/database_cleaner/mongo/deletion.rb
107
105
  - lib/database_cleaner/mongo/version.rb
108
106
  homepage: https://github.com/DatabaseCleaner/database_cleaner-mongo
109
107
  licenses:
@@ -124,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
122
  - !ruby/object:Gem::Version
125
123
  version: '0'
126
124
  requirements: []
127
- rubygems_version: 3.0.4
125
+ rubygems_version: 3.0.3
128
126
  signing_key:
129
127
  specification_version: 4
130
128
  summary: Strategies for cleaning databases using Mongo. Can be used to ensure a clean
@@ -1,46 +0,0 @@
1
- PATH
2
- remote: ../..
3
- specs:
4
- database_cleaner (1.8.0)
5
-
6
- PATH
7
- remote: .
8
- specs:
9
- database_cleaner-mongo (1.8.0)
10
- database_cleaner (~> 1.8.0)
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.2
@@ -1,16 +0,0 @@
1
- module DatabaseCleaner
2
- module Mongo
3
- def self.available_strategies
4
- %w[truncation]
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,62 +0,0 @@
1
- require 'database_cleaner/mongo/base'
2
- require 'database_cleaner/generic/truncation'
3
- require 'database_cleaner/mongo/truncation_mixin'
4
- module DatabaseCleaner
5
- module Mongo
6
- class Truncation
7
- include ::DatabaseCleaner::Generic::Truncation
8
- include TruncationMixin
9
- include Base
10
- private
11
-
12
- def database
13
- db
14
- end
15
-
16
- def collections_cache
17
- @@collections_cache ||= {}
18
- end
19
-
20
- def mongoid_collection_names
21
- @@mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names|
22
- ObjectSpace.each_object(Class) do |klass|
23
- (names[klass.db.name] << klass.collection_name) if valid_collection_name?(klass)
24
- end
25
- end
26
- end
27
-
28
- def not_caching(db_name, list)
29
- @@not_caching ||= {}
30
-
31
- unless @@not_caching.has_key?(db_name)
32
- @@not_caching[db_name] = true
33
-
34
- puts "Not caching collection names for db #{db_name}. Missing these from models: #{list}"
35
- end
36
- end
37
-
38
- def collections
39
- return collections_cache[database.name] if collections_cache.has_key?(database.name)
40
- db_collections = database.collections.select { |c| c.name !~ /^system\./ }
41
-
42
- missing_collections = mongoid_collection_names[database.name] - db_collections.map(&:name)
43
-
44
- if missing_collections.empty?
45
- collections_cache[database.name] = db_collections
46
- else
47
- not_caching(database.name, missing_collections)
48
- end
49
-
50
- db_collections
51
- end
52
-
53
- private
54
-
55
- def valid_collection_name?(klass)
56
- klass.ancestors.map(&:to_s).include?('Mongoid::Document') &&
57
- !klass.embedded &&
58
- !klass.collection_name.empty?
59
- end
60
- end
61
- end
62
- 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