database_cleaner-mongo 1.8.0.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7a61efb7736a087e292db7d06c9ea24bfd3c25770936002490adea871733ee65
4
+ data.tar.gz: db0b6670158490e5162dc963c4be39590febf7b24f0655d959e13791b683e6b1
5
+ SHA512:
6
+ metadata.gz: c64bf79b858e846143f1148542762809130e1ac2211a941d6da83eb35a241e9ccdae59150b4cca355b20a3c0c7cd7e63c94aae442dad162f69f57b4acdde2abb
7
+ data.tar.gz: eeb693a9770c80ae64629c84f433151a2051ee504ead8b02dfaba32e768b8f8eab38f2a197bebda7f4207cf604bf304459bbc934ea043be76546af82994378ef
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.9
5
+ before_install: gem install bundler -v 1.17.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in database_cleaner-mongo.gemspec
6
+ gemspec
7
+
8
+ gem "database_cleaner", path: "../.."
@@ -0,0 +1,46 @@
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
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2009 Ben Mabey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # Database Cleaner Adapter for Mongo
2
+
3
+ [![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner-mongo.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner-mongo)
4
+ [![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner-mongo/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner-mongo)
5
+
6
+ Clean your Mongo databases with Database Cleaner.
7
+
8
+ See https://github.com/DatabaseCleaner/database_cleaner for more information.
9
+
10
+ ## Installation
11
+
12
+ ```ruby
13
+ # Gemfile
14
+ group :test do
15
+ gem 'database_cleaner-mongo'
16
+ end
17
+ ```
18
+
19
+ ## Supported Strategies
20
+
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)
37
+
38
+ ## Configuration options
39
+
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>
54
+
55
+ ## COPYRIGHT
56
+
57
+ See [LICENSE] for details.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "database_cleaner/mongo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle check || bundle install
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "database_cleaner/mongo/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "database_cleaner-mongo"
8
+ spec.version = DatabaseCleaner::Mongo::VERSION
9
+ spec.authors = ["Ernesto Tagwerker"]
10
+ spec.email = ["ernesto@ombulabs.com"]
11
+
12
+ spec.summary = "Strategies for cleaning databases using Mongo. Can be used to ensure a clean state for testing."
13
+ spec.description = "Strategies for cleaning databases using Mongo. Can be used to ensure a clean state for testing."
14
+ spec.homepage = "https://github.com/DatabaseCleaner/database_cleaner-mongo"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "database_cleaner", "~> 1.8.0"
25
+ spec.add_dependency "mongo"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
@@ -0,0 +1 @@
1
+ require "database_cleaner/mongo"
@@ -0,0 +1,10 @@
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
10
+
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,62 @@
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
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module Mongo
3
+ VERSION = "1.8.0.beta"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: database_cleaner-mongo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.8.0.beta
5
+ platform: ruby
6
+ authors:
7
+ - Ernesto Tagwerker
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: database_cleaner
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Strategies for cleaning databases using Mongo. Can be used to ensure
84
+ a clean state for testing.
85
+ email:
86
+ - ernesto@ombulabs.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - database_cleaner-mongo.gemspec
102
+ - lib/database_cleaner-mongo.rb
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
107
+ - lib/database_cleaner/mongo/version.rb
108
+ homepage: https://github.com/DatabaseCleaner/database_cleaner-mongo
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">"
124
+ - !ruby/object:Gem::Version
125
+ version: 1.3.1
126
+ requirements: []
127
+ rubygems_version: 3.0.4
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Strategies for cleaning databases using Mongo. Can be used to ensure a clean
131
+ state for testing.
132
+ test_files: []