mongoid_cleaner 1.0.0 → 1.1.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
  SHA1:
3
- metadata.gz: fdc85738b916058da39a76bb73892bafd80e3c58
4
- data.tar.gz: 2e37d7083ae4c4eb0d9ff567197c71bed6a5defe
3
+ metadata.gz: 0d8c7375290440e533630aba4b66a36217cd933b
4
+ data.tar.gz: a74702cb43805411e46c4b3f681d383e0f7b6bb9
5
5
  SHA512:
6
- metadata.gz: eaf57c59b37c224831b08daeba6bf308a4d8f2f46599fce644567b5f68824cef628d0439d30f4773f5ca9da451143366ee598593e120b7b82ffba92b902f0369
7
- data.tar.gz: 47c7a47d4244a2af40f6e2c95d0b65bf2cf14e49d6fae34142399ec6d2d796bc4f2c953d4f40775d53d7a25292774843c75d233773de90af05b2eb1c34eb9dbc
6
+ metadata.gz: 6f57547909b9fa0bc81f0529b7679f56dc454a9e0724a32caca262e7d4325fa7012410cb9c2f597e994ae6e7286dc51c7fbfe5bf12a22842436dd325e24aa376
7
+ data.tar.gz: b6ff6fcc604dfd3fc398f078e016af7b42477cfbd2e165411f264ac69e84077b48f18447917a01a165ca8a9cb148f84667fbea344f7e9bf014d586dcf92449ee
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ AllCops:
2
+ Exclude:
3
+ - '**/vendor/**/*'
data/.travis.yml CHANGED
@@ -4,6 +4,9 @@ cache:
4
4
  - bundler
5
5
  before_install:
6
6
  - gem update --remote bundler
7
+ gemfile:
8
+ - gemfiles/mongoid4.gemfile
9
+ - gemfiles/mongoid5.gemfile
7
10
  env:
8
11
  matrix:
9
12
  - MONGODB=3.0.3 CONFIG="--config /tmp/mongodb-wiredtiger.conf"
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ Mon Oct 19 18:30:13 2015 +0200 Laurent Arnoud <laurent.arnoud@td-berlin.com>
2
+
3
+ * Mongoid 5 compatibility, thanks to: Maik Kempe <mkempe@bitaculous.com>
data/README.md CHANGED
@@ -1,16 +1,23 @@
1
1
  # MongoidCleaner
2
+ [![Build Status](https://travis-ci.org/td-berlin/mongoid_cleaner.svg)](https://travis-ci.org/td-berlin/mongoid_cleaner)
2
3
 
3
- ![Build Status](https://magnum.travis-ci.com/td-berlin/mongoid_cleaner.svg?token=1Pjyqv334JwTadXqcays&branch=master)
4
+ MongoidCleaner is an alternative for [DatabaseCleaner](https://github.com/DatabaseCleaner/database_cleaner)
5
+ for projects using [MongoDB](https://www.mongodb.org/) along with [Mongoid](http://mongoid.org/en/mongoid/index.html).
6
+ Besides the `truncate` strategy, this gem also provides faster `drop` strategy. It runs with Mongoid versions 4 and 5.
4
7
 
5
- MongoidCleaner with drop and truncation strategy
6
8
 
7
9
  ## Why?
8
10
 
9
- * [database_cleaner](https://github.com/DatabaseCleaner/database_cleaner) exists
10
- but it don't support [MongoDB 3](https://github.com/DatabaseCleaner/database_cleaner/issues/348).
11
+ DatabaseCleaner always served our needs well, unfortunately it didn't support [MongoDB 3 running on Wired Tiger](https://github.com/DatabaseCleaner/database_cleaner/pull/343)
12
+ for quite some time, so we decided to build our own specialised solution.
11
13
 
12
- * Also we discovered that droping collection is more faster than truncation
13
- strategy.
14
+ Also, removing all the documents from a collection requires much more work: Freeing the document's storage, clearing the index entries that point to the document, etc..
15
+ The benefit of simply dropping a collection is that it is much faster.
16
+
17
+ ## Possible drawbacks
18
+
19
+ We haven't experienced any problems so far, but dropping a collection will also remove the collections indexes.
20
+ Feel free to report any issues related to that.
14
21
 
15
22
  ## Installation
16
23
 
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'mongoid', '~> 4'
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'mongoid', '~> 5'
4
+
5
+ gemspec path: "../"
@@ -1,4 +1,4 @@
1
1
  # :nodoc:
2
2
  module MongoidCleaner
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
@@ -8,6 +8,10 @@ module MongoidCleaner
8
8
  class << self
9
9
  attr_reader :strategy
10
10
 
11
+ def mongoid_version
12
+ @mongoid_version ||= Mongoid::VERSION.split('.').first.to_i
13
+ end
14
+
11
15
  def available_strategies
12
16
  @available_strategies ||= %w(truncate drop)
13
17
  end
@@ -28,14 +32,24 @@ module MongoidCleaner
28
32
  @session ||= Mongoid.default_session
29
33
  end
30
34
 
31
- # @return Array mongoid collections
32
- def collections
35
+ # return with mongoid 5 `Mongo::Operation::Result`
36
+ # return with mongoid 4 `BSON::Document`
37
+ def collections_filter
33
38
  session.command(
34
39
  listCollections: 1,
35
40
  filter: {
36
41
  name:
37
42
  { '$not' => /.?system\.|\$/ }
38
- })['cursor']['firstBatch'].map { |c| c['name'] }
43
+ })
44
+ end
45
+
46
+ # @return Array mongoid collections names
47
+ def collections
48
+ if mongoid_version > 4
49
+ collections_filter.first[:cursor][:firstBatch].map { |c| c['name'] }
50
+ else
51
+ collections_filter['cursor']['firstBatch'].map { |c| c['name'] }
52
+ end
39
53
  end
40
54
 
41
55
  def collections_with_options
@@ -56,7 +70,11 @@ module MongoidCleaner
56
70
 
57
71
  # @return Boolean
58
72
  def truncate
59
- collections_with_options.each { |c| session[c].find.remove_all }
73
+ if mongoid_version > 4
74
+ collections_with_options.each { |c| session[c].find.delete_many }
75
+ else
76
+ collections_with_options.each { |c| session[c].find.remove_all }
77
+ end
60
78
  true
61
79
  end
62
80
 
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.9'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'rubocop', '~> 0.31'
24
- spec.add_dependency 'mongoid', '~> 4.0'
24
+ spec.add_dependency 'mongoid', '>= 4.0'
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TD Dashboys
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-16 00:00:00.000000000 Z
11
+ date: 2015-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,14 +56,14 @@ dependencies:
56
56
  name: mongoid
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '4.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '4.0'
69
69
  description:
@@ -74,12 +74,16 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
+ - ".rubocop.yml"
77
78
  - ".travis.yml"
79
+ - CHANGELOG.md
78
80
  - Gemfile
79
81
  - LICENSE.txt
80
82
  - README.md
81
83
  - Rakefile
82
84
  - configs/mongodb-wiredtiger.conf
85
+ - gemfiles/mongoid4.gemfile
86
+ - gemfiles/mongoid5.gemfile
83
87
  - lib/mongoid_cleaner.rb
84
88
  - lib/mongoid_cleaner/version.rb
85
89
  - mongoid_cleaner.gemspec
@@ -103,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
107
  version: '0'
104
108
  requirements: []
105
109
  rubyforge_project:
106
- rubygems_version: 2.4.5
110
+ rubygems_version: 2.4.5.1
107
111
  signing_key:
108
112
  specification_version: 4
109
113
  summary: MongoidCleaner with drop and truncation strategy