database_cleaner-mongoid 1.8.0 → 1.8.1

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: 7c969d9ee56f6a3f591d7deb4c4b8b9e1d2713ffef29cb236dbbe4294090ebdf
4
- data.tar.gz: 0a848d2ff860135f514ef1553b49d20dc28d918304c0f068815778516d99cb6d
3
+ metadata.gz: 311f86c29e38791d5046c4b377a44713b127c75fd8c2f0bd7fb879f0d22a18df
4
+ data.tar.gz: c73bc11fa65341aabde2a7563271512a825b401ea9a4604c904f61a7ee3b03cf
5
5
  SHA512:
6
- metadata.gz: d07475b527e1721cdde5811650c13a08f7e5a82f68430c75b8d05b60a5593e73f6c56c43c38910f025eba67a6eddc2fea439280c9ba390a127a570e64195e917
7
- data.tar.gz: 7c1d05ed6a46218db54f33291dfc412b6ee758445774a2912a8b0cb30b47b1ee931871a6ab25b6ebeca636057f0db702641643aff7957a3cebabecdb035f4679
6
+ metadata.gz: 7003aa892b7f56b04b5e17cee7de5f632df9d44b9391e239c76f15f43cee0774410dc1071606e81741064cda6ed69d133dc4ce6fa6f96159379951a54f2bf1aa
7
+ data.tar.gz: 5670338f7592343076f4de02008a4cc205bb3918aa8d6297dc8694e32f0dbcf3a1e28e79d328182ce605ae427c04f796056c526d3dad51a371b42178b04f3190
@@ -1,4 +1,4 @@
1
- sudo: false
1
+
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.2.9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- database_cleaner (1.8.0)
4
+ database_cleaner (1.8.1)
5
5
 
6
6
  PATH
7
7
  remote: ..
@@ -13,7 +13,7 @@ PATH
13
13
  PATH
14
14
  remote: .
15
15
  specs:
16
- database_cleaner-mongoid (1.8.0)
16
+ database_cleaner-mongoid (1.8.1)
17
17
  database_cleaner (~> 1.8.0)
18
18
  database_cleaner-mongo (~> 1.8.0)
19
19
  mongoid
@@ -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 Mongo2
3
- module TruncationMixin
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
+
@@ -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/mongo/truncation_mixin'
4
- require 'database_cleaner/mongo2/truncation_mixin'
5
- require 'database_cleaner/moped/truncation_base'
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::Mongo::TruncationMixin
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::Moped::TruncationBase
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::Mongo2::TruncationMixin
44
+ include ::DatabaseCleaner::Mongoid::Mongo2TruncationMixin
45
45
 
46
46
  end
47
47
  end
@@ -1,5 +1,5 @@
1
1
  module DatabaseCleaner
2
2
  module Mongoid
3
- VERSION = "1.8.0"
3
+ VERSION = "1.8.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_cleaner-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernesto Tagwerker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-30 00:00:00.000000000 Z
11
+ date: 2020-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: database_cleaner
@@ -114,9 +114,11 @@ files:
114
114
  - bin/setup
115
115
  - database_cleaner-mongoid.gemspec
116
116
  - lib/database_cleaner-mongoid.rb
117
- - lib/database_cleaner/mongo2/truncation_mixin.rb
118
117
  - lib/database_cleaner/mongoid.rb
119
118
  - lib/database_cleaner/mongoid/base.rb
119
+ - lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb
120
+ - lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb
121
+ - lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb
120
122
  - lib/database_cleaner/mongoid/truncation.rb
121
123
  - lib/database_cleaner/mongoid/version.rb
122
124
  homepage: https://github.com/DatabaseCleaner/database_cleaner-mongoid