mongoid-multitenancy 2.0.2 → 2.0.4

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
- SHA1:
3
- metadata.gz: 620341a8f6aca85ff9aa07f1d1ef64350c83761b
4
- data.tar.gz: 9084759b68045627f30ebda29c78bbfbc1bde545
2
+ SHA256:
3
+ metadata.gz: 6b73b7aa6b228218cdc8f7984b1e1b6ba340f06f23ad4730e533c7eda4fe9023
4
+ data.tar.gz: bf9b89578b7afef058724f6e3170b5158590894d6267d419df9675c1fa786e08
5
5
  SHA512:
6
- metadata.gz: 219017bd332374bb672778f8c100a237c3e97d065bd4fe4d0ca8299f382260f222bab417ed9610d4ab6afc9ea37bf73562680b61ad94a3bca00cadcda1ca5861
7
- data.tar.gz: 5fb5ec2e0f34dd22a9b2b4c06a158e035370f38baad826da42fd0d7e4365043eb2ad4870a25ad62696afa87f1c548cf1a07771dbcdccbd47f5c09816a9f8a7b5
6
+ metadata.gz: 59a416b22144c02a3617356317421b27b6bb73947556c96c34ce36e67525d2b6a84a15bc5cd9f66d0acd9efd93e88cccaa1273c1dd4d3e6a08651acd294f5777
7
+ data.tar.gz: 3eefea63c163088fd87870cbe58d04aa8f17df612da993c552f666d01ebb4d9bf520715735f1afc04a234fba7a25573ba3e06b37bbc2c6c95951e8f4370da579
data/.travis.yml CHANGED
@@ -6,6 +6,8 @@ rvm:
6
6
  gemfile:
7
7
  - gemfiles/Gemfile.mongoid-6
8
8
  - gemfiles/Gemfile.mongoid-7
9
+ - gemfiles/Gemfile.mongoid-8
10
+ - gemfiles/Gemfile.mongoid-9
9
11
  - Gemfile
10
12
  services:
11
13
  - mongodb
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.0.4] - 2024-06-17
8
+ ### Fixed
9
+
10
+ * Full Support of mongoid 8 & 9
11
+
12
+ ## [2.0.3] - 2020-06-25
13
+ ### Fixed
14
+
15
+ * Full Support of mongoid 7
16
+
7
17
  ## [2.0.2] - 2018-08-23
8
18
  ### Added
9
19
 
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'rake'
4
4
 
5
5
  group :test do
6
- gem 'database_cleaner'
6
+ gem 'database_cleaner-mongoid'
7
7
  gem 'coveralls', require: false
8
8
  gem 'rspec', '~> 3.1'
9
9
  gem 'yard'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # mongoid-multitenancy [![Build Status](https://api.travis-ci.org/PerfectMemory/mongoid-multitenancy.png?branch=master)](https://travis-ci.org/PerfectMemory/mongoid-multitenancy) [![Coverage Status](https://coveralls.io/repos/PerfectMemory/mongoid-multitenancy/badge.svg?branch=master&service=github)](https://coveralls.io/github/PerfectMemory/mongoid-multitenancy?branch=master) [![Code Climate](https://codeclimate.com/github/PerfectMemory/mongoid-multitenancy.png)](https://codeclimate.com/github/PerfectMemory/mongoid-multitenancy) [![Dependency Status](https://gemnasium.com/PerfectMemory/mongoid-multitenancy.png)](https://gemnasium.com/PerfectMemory/mongoid-multitenancy)
1
+ # mongoid-multitenancy [![Build Status](https://api.travis-ci.org/PerfectMemory/mongoid-multitenancy.png?branch=master)](https://travis-ci.org/PerfectMemory/mongoid-multitenancy) [![Coverage Status](https://coveralls.io/repos/github/PerfectMemory/mongoid-multitenancy/badge.svg?branch=master)](https://coveralls.io/github/PerfectMemory/mongoid-multitenancy?branch=master) [![Code Climate](https://codeclimate.com/github/PerfectMemory/mongoid-multitenancy.png)](https://codeclimate.com/github/PerfectMemory/mongoid-multitenancy)
2
2
 
3
3
  mongoid-multitenancy adds the ability to scope [Mongoid](https://github.com/mongoid/mongoid) models to a tenant in a **shared database strategy**. Tenants are represented by a tenant model, such as `Client`. mongoid-multitenancy will help you set the current tenant on each request and ensures that all 'tenant models' are always properly scoped to the current tenant: when viewing, searching and creating.
4
4
 
@@ -15,7 +15,7 @@ In addition, mongoid-multitenancy:
15
15
  Compatibility
16
16
  ===============
17
17
 
18
- mongoid-multitenancy 2.0 is only compatible with mongoid 6. For mongoid 4 & 5 compatiblity, use mongoid-multitenancy 1.2.
18
+ mongoid-multitenancy 2 is compatible with mongoid 6/7/8/9. For mongoid 4/5 compatiblity, use mongoid-multitenancy 1.2.
19
19
 
20
20
  Installation
21
21
  ===============
@@ -229,13 +229,13 @@ end
229
229
  Mongoid indexes
230
230
  -------------------
231
231
 
232
- mongoid-multitenancy automatically adds the tenant foreign key in all your mongoid indexes to avoid to redefine all your validators. If you prefer to define manually the indexes, you can use the option `full_indexes: false`.
232
+ mongoid-multitenancy automatically adds the tenant foreign key in all your mongoid indexes to avoid to redefine all your validators. If you prefer to define the indexes manually, you can use the option `full_indexes: false` on the tenant or `full_index: true/false` on the indexes.
233
233
 
234
234
  To create a single index on the tenant field, you can use the option `index: true` like any `belongs_to` declaration (false by default)
235
235
 
236
- On the example below, only one indexe will be created:
236
+ On the example below, only one index will be created:
237
237
 
238
- * { 'title_id' => 1, 'tenant_id' => 1 }
238
+ * { 'tenant_id' => 1, 'title' => 1 }
239
239
 
240
240
  ```ruby
241
241
  class Article
@@ -250,10 +250,11 @@ class Article
250
250
  end
251
251
  ```
252
252
 
253
- On the example below, 2 indexes will be created:
253
+ On the example below, 3 indexes will be created:
254
254
 
255
255
  * { 'tenant_id' => 1 }
256
- * { 'title_id' => 1 }
256
+ * { 'tenant_id' => 1, 'title' => 1 }
257
+ * { 'name' => 1 }
257
258
 
258
259
  ```ruby
259
260
  class Article
@@ -263,8 +264,10 @@ class Article
263
264
  tenant :tenant, index: true
264
265
 
265
266
  field :title
267
+ field :name
266
268
 
267
269
  index({ :title => 1 })
270
+ index({ :name => 1 }, { full_index: false })
268
271
  end
269
272
  ```
270
273
 
@@ -5,7 +5,7 @@ gem 'mongoid', '~> 6.0'
5
5
  gem 'rake'
6
6
 
7
7
  group :test do
8
- gem 'database_cleaner'
8
+ gem 'database_cleaner-mongoid'
9
9
  gem 'coveralls', require: false
10
10
  gem 'rspec', '~> 3.1'
11
11
  gem 'yard'
@@ -5,7 +5,7 @@ gem 'mongoid', '~> 7.0'
5
5
  gem 'rake'
6
6
 
7
7
  group :test do
8
- gem 'database_cleaner'
8
+ gem 'database_cleaner-mongoid'
9
9
  gem 'coveralls', require: false
10
10
  gem 'rspec', '~> 3.1'
11
11
  gem 'yard'
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'mongoid', '~> 8.0'
4
+
5
+ gem 'rake'
6
+
7
+ group :test do
8
+ gem 'database_cleaner-mongoid'
9
+ gem 'coveralls', require: false
10
+ gem 'rspec', '~> 3.1'
11
+ gem 'yard'
12
+ gem 'mongoid-rspec', git: 'https://github.com/mongoid-rspec/mongoid-rspec.git'
13
+ gem 'rubocop', require: false
14
+ end
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'mongoid', '~> 9.0'
4
+
5
+ gem 'rake'
6
+
7
+ group :test do
8
+ gem 'database_cleaner-mongoid'
9
+ gem 'coveralls', require: false
10
+ gem 'rspec', '~> 3.1'
11
+ gem 'yard'
12
+ gem 'mongoid-rspec', git: 'https://github.com/mongoid-rspec/mongoid-rspec.git'
13
+ gem 'rubocop', require: false
14
+ end
@@ -87,15 +87,17 @@ module Mongoid
87
87
 
88
88
  # Redefine 'index' to include the tenant field in first position
89
89
  def index(spec, options = nil)
90
- if tenant_options[:full_indexes]
90
+ super_options = (options || {}).dup
91
+ full_index = super_options.delete(:full_index)
92
+ if full_index.nil? ? tenant_options[:full_indexes] : full_index
91
93
  spec = { tenant_field => 1 }.merge(spec)
92
94
  end
93
95
 
94
- super(spec, options)
96
+ super(spec, super_options)
95
97
  end
96
98
 
97
99
  # Redefine 'delete_all' to take in account the default scope
98
- def delete_all(conditions = nil)
100
+ def delete_all(conditions = {})
99
101
  scoped.where(conditions).delete
100
102
  end
101
103
 
@@ -154,7 +156,7 @@ module Mongoid
154
156
  where(tenant_field => tenant_id)
155
157
  end
156
158
  else
157
- where(nil)
159
+ all
158
160
  end
159
161
  }
160
162
 
@@ -1,6 +1,6 @@
1
1
  module Mongoid
2
2
  module Multitenancy
3
3
  # Version
4
- VERSION = '2.0.2'.freeze
4
+ VERSION = '2.0.4'.freeze
5
5
  end
6
6
  end
@@ -15,5 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ['lib']
16
16
  gem.version = Mongoid::Multitenancy::VERSION
17
17
 
18
- gem.add_dependency('mongoid', '~> 6', '< 8')
18
+ gem.add_dependency('mongoid', '>= 6', '< 10')
19
19
  end
@@ -9,27 +9,62 @@ describe 'tenant' do
9
9
  Mongoid::Multitenancy.current_tenant = client
10
10
  end
11
11
 
12
- context 'without index: true' do
13
- it 'does not create an index' do
14
- expect(Immutable).not_to have_index_for(tenant_id: 1)
12
+ describe 'tenant full_indexes option' do
13
+ context 'without index option' do
14
+ it 'does not create an index' do
15
+ expect(IndexableWithoutIndex).not_to have_index_for(tenant_id: 1)
16
+ end
15
17
  end
16
- end
17
18
 
18
- context 'with index: true' do
19
- it 'creates an index' do
20
- expect(Indexable).to have_index_for(tenant_id: 1)
19
+ context 'with index: false' do
20
+ it 'does not create an index' do
21
+ expect(IndexableWithIndexFalse).not_to have_index_for(tenant_id: 1)
22
+ end
21
23
  end
22
- end
23
24
 
24
- context 'with full_indexes: true' do
25
- it 'add the tenant field on each index' do
26
- expect(Immutable).to have_index_for(tenant_id: 1, title: 1)
25
+ context 'with index: true' do
26
+ it 'creates an index' do
27
+ expect(IndexableWithIndexTrue).to have_index_for(tenant_id: 1)
28
+ end
27
29
  end
28
30
  end
29
31
 
30
- context 'with full_indexes: false' do
31
- it 'does not add the tenant field on each index' do
32
- expect(Indexable).not_to have_index_for(tenant_id: 1, title: 1)
32
+ describe 'index full_index option' do
33
+ context 'without tenant full_indexes option specified' do
34
+ it 'adds the tenant field on each index' do
35
+ expect(IndexableWithoutFullIndexes).to have_index_for(tenant_id: 1, title: 1)
36
+ end
37
+
38
+ it 'adds the tenant field on the index with full_index: true' do
39
+ expect(IndexableWithoutFullIndexes).to have_index_for(tenant_id: 1, name: 1)
40
+ end
41
+
42
+ it 'does not add the tenant field on the index with full_index: false' do
43
+ expect(IndexableWithoutFullIndexes).not_to have_index_for(tenant_id: 1, slug: 1)
44
+ expect(IndexableWithoutFullIndexes).to have_index_for(slug: 1)
45
+ end
46
+ end
47
+
48
+ context 'with full_indexes: true' do
49
+ it 'adds the tenant field on each index' do
50
+ expect(IndexableWithFullIndexesTrue).to have_index_for(tenant_id: 1, title: 1)
51
+ end
52
+
53
+ it 'does not add the tenant field on the index with full_index: false' do
54
+ expect(IndexableWithFullIndexesTrue).not_to have_index_for(tenant_id: 1, name: 1)
55
+ expect(IndexableWithFullIndexesTrue).to have_index_for(name: 1)
56
+ end
57
+ end
58
+
59
+ context 'with full_indexes: false' do
60
+ it 'does not add the tenant field on each index' do
61
+ expect(IndexableWithFullIndexesFalse).not_to have_index_for(tenant_id: 1, title: 1)
62
+ expect(IndexableWithFullIndexesFalse).to have_index_for(title: 1)
63
+ end
64
+
65
+ it 'does add the tenant field on the index with full_index: true' do
66
+ expect(IndexableWithFullIndexesFalse).to have_index_for(tenant_id: 1, name: 1)
67
+ end
33
68
  end
34
69
  end
35
70
  end
@@ -1,10 +1,61 @@
1
- class Indexable
1
+ class IndexableWithoutIndex
2
+ include Mongoid::Document
3
+ include Mongoid::Multitenancy::Document
4
+
5
+ tenant :tenant, class_name: 'Account'
6
+ end
7
+
8
+ class IndexableWithIndexTrue
9
+ include Mongoid::Document
10
+ include Mongoid::Multitenancy::Document
11
+
12
+ tenant :tenant, class_name: 'Account', index: true
13
+ end
14
+
15
+ class IndexableWithIndexFalse
16
+ include Mongoid::Document
17
+ include Mongoid::Multitenancy::Document
18
+
19
+ tenant :tenant, class_name: 'Account', index: false
20
+ end
21
+
22
+ class IndexableWithoutFullIndexes
23
+ include Mongoid::Document
24
+ include Mongoid::Multitenancy::Document
25
+
26
+ field :title, type: String
27
+ field :name, type: String
28
+ field :slug, type: String
29
+
30
+ tenant :tenant, class_name: 'Account'
31
+
32
+ index(title: 1)
33
+ index({ name: 1 }, { full_index: true })
34
+ index({ slug: 1 }, { full_index: false })
35
+ end
36
+
37
+ class IndexableWithFullIndexesFalse
38
+ include Mongoid::Document
39
+ include Mongoid::Multitenancy::Document
40
+
41
+ field :title, type: String
42
+ field :name, type: String
43
+
44
+ tenant :tenant, class_name: 'Account', full_indexes: false
45
+
46
+ index(title: 1)
47
+ index({ name: 1 }, { full_index: true })
48
+ end
49
+
50
+ class IndexableWithFullIndexesTrue
2
51
  include Mongoid::Document
3
52
  include Mongoid::Multitenancy::Document
4
53
 
5
54
  field :title, type: String
55
+ field :name, type: String
6
56
 
7
- tenant :tenant, class_name: 'Account', index: true, full_indexes: false
57
+ tenant :tenant, class_name: 'Account', full_indexes: true
8
58
 
9
59
  index(title: 1)
60
+ index({ name: 1 }, { full_index: false })
10
61
  end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ MODELS = File.join(File.dirname(__FILE__), 'models')
2
2
 
3
3
  require 'simplecov'
4
4
  require 'coveralls'
5
- require 'database_cleaner'
5
+ require 'database_cleaner-mongoid'
6
6
 
7
7
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
8
  SimpleCov::Formatter::HTMLFormatter,
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-multitenancy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aymeric Brisse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-23 00:00:00.000000000 Z
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '6'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '8'
22
+ version: '10'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '6'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '8'
32
+ version: '10'
33
33
  description: MultiTenancy with Mongoid
34
34
  email:
35
35
  - aymeric.brisse@mperfect-memory.com
@@ -47,6 +47,8 @@ files:
47
47
  - Rakefile
48
48
  - gemfiles/Gemfile.mongoid-6
49
49
  - gemfiles/Gemfile.mongoid-7
50
+ - gemfiles/Gemfile.mongoid-8
51
+ - gemfiles/Gemfile.mongoid-9
50
52
  - lib/mongoid-multitenancy.rb
51
53
  - lib/mongoid/multitenancy.rb
52
54
  - lib/mongoid/multitenancy/document.rb
@@ -95,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
97
  - !ruby/object:Gem::Version
96
98
  version: '0'
97
99
  requirements: []
98
- rubyforge_project:
99
- rubygems_version: 2.6.14.1
100
+ rubygems_version: 3.3.27
100
101
  signing_key:
101
102
  specification_version: 4
102
103
  summary: Support of a multi-tenant database with Mongoid