mongoid-multitenancy 1.2.0 → 2.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: bc62ee7dad2407f285292511b1a3ff9487b2f658
4
- data.tar.gz: de93ec4f6f8182bd4307c9cc865b585f215d9a68
3
+ metadata.gz: 431219928a15faa3df3004d3b81b840bc8650691
4
+ data.tar.gz: 41c7101a950c1ae7539912038befff3c9e4cac63
5
5
  SHA512:
6
- metadata.gz: 1bbfd25a05be1f5bb1a873fa53f42df8546b6cc24a568b846500d6b8e429df9ebb6781e21fdac50b91f34f95a415f0c8a83dd9de0017e0d86919828c215b13b2
7
- data.tar.gz: 747a8e3b7e5cc1ee8daaa5713a3e39f82978a27c10e0dac8bc4b7ef94eb38b561c982c8349252a6265b2dee08fc0981a796ff9149776c02f080687f9479f6274
6
+ metadata.gz: 6c7e4c5902e9da5050c1bf14797a93d06a1303fa61fed4ad9cb6b32ea57309f6abbe8ecef530f37457e9474fc18bd2eeb99812229c67abbaf9e8a7b3cceec1fe
7
+ data.tar.gz: 14df29dad2f6946275bbc152823003a04c701b44f3bac4774fdbbf11faabe7d4d5aad0b1f49b7f544d298c7ef6d0ed056874fe8a26c047b09de7986ddc1c13b6
data/.travis.yml CHANGED
@@ -1,13 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.0
5
- - 2.2.0
3
+ - 2.2.2
6
4
  - 2.3.0
7
- - jruby
5
+ - 2.4.1
8
6
  gemfile:
9
- - gemfiles/Gemfile.mongoid-4.0
10
- - gemfiles/Gemfile.mongoid-5.0
11
7
  - Gemfile
12
8
  services:
13
9
  - mongodb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 2.0
2
+
3
+ ### New Features
4
+
5
+ * Add support for mongoid 6
6
+ * Remove support for mongoid 4 & 5
7
+
8
+ ## 1.2
9
+
10
+ ### New Features
11
+
12
+ * Add *exclude_shared* option for the TenantUniquenessValidator
13
+
1
14
  ## 1.1
2
15
 
3
16
  ### New Features
@@ -12,7 +25,7 @@
12
25
 
13
26
  ### New Features
14
27
 
15
- * Adds support for mongoid 5
28
+ * Add support for mongoid 5
16
29
 
17
30
  ### Major Changes (Backwards Incompatible)
18
31
 
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'mongoid', '~> 5.1'
3
+ gem 'mongoid', '~> 6.0'
4
4
 
5
5
  gem 'rake', '~> 11.0'
6
6
 
@@ -9,7 +9,7 @@ group :test do
9
9
  gem 'coveralls', require: false
10
10
  gem 'rspec', '~> 3.1'
11
11
  gem 'yard', '~> 0.8'
12
- gem 'mongoid-rspec', '~> 3.0'
12
+ gem 'mongoid-rspec', git: 'https://github.com/mongoid-rspec/mongoid-rspec.git'
13
13
  gem 'rubocop', require: false
14
14
  end
15
15
 
data/README.md CHANGED
@@ -12,12 +12,17 @@ In addition, mongoid-multitenancy:
12
12
  * is thread safe
13
13
  * redefines some mongoid functions like `index`, `validates_with` and `delete_all` to take in account the multitenancy.
14
14
 
15
+ Compatibility
16
+ ===============
17
+
18
+ mongoid-multitenancy 2.0 is only compatible with mongoid 6. For mongoid 4 & 5 compatiblity, use mongoid-multitenancy 1.2.
19
+
15
20
  Installation
16
21
  ===============
17
22
 
18
23
  Add this line to your application's Gemfile:
19
24
 
20
- gem 'mongoid-multitenancy'
25
+ gem 'mongoid-multitenancy', '~> 2.0'
21
26
 
22
27
  And then execute:
23
28
 
@@ -74,7 +79,7 @@ class Article
74
79
  include Mongoid::Document
75
80
  include Mongoid::Multitenancy::Document
76
81
 
77
- tenant(:client)
82
+ tenant(:tenant)
78
83
 
79
84
  field :title, :type => String
80
85
  end
@@ -101,15 +106,15 @@ Some examples to illustrate this behavior:
101
106
  Mongoid::Multitenancy.current_tenant = Client.find_by(:name => 'Perfect Memory') # => <#Client _id:50ca04b86c82bfc125000025, :name: "Perfect Memory">
102
107
 
103
108
  # All searches are scoped by the tenant, the following searches will only return objects belonging to the current client.
104
- Article.all # => all articles where client_id => 50ca04b86c82bfc125000025
109
+ Article.all # => all articles where tenant_id => 50ca04b86c82bfc125000025
105
110
 
106
111
  # New objects are scoped to the current tenant
107
112
  article = Article.new(:title => 'New blog')
108
- article.save # => <#Article _id: 50ca04b86c82bfc125000044, title: 'New blog', client_id: 50ca04b86c82bfc125000025>
113
+ article.save # => <#Article _id: 50ca04b86c82bfc125000044, title: 'New blog', tenant_id: 50ca04b86c82bfc125000025>
109
114
 
110
115
  # It can make the tenant field immutable once it is persisted to avoid inconsistency
111
116
  article.persisted? # => true
112
- article.client = another_client
117
+ article.tenant = another_client
113
118
  article.valid? # => false
114
119
  ```
115
120
 
@@ -124,21 +129,21 @@ class Article
124
129
  include Mongoid::Document
125
130
  include Mongoid::Multitenancy::Document
126
131
 
127
- tenant(:client, optional: true)
132
+ tenant(:tenant, optional: true)
128
133
 
129
134
  field :title, :type => String
130
135
  end
131
136
 
132
137
  Mongoid::Multitenancy.with_tenant(client_instance) do
133
- Article.all # => all articles where client_id.in [50ca04b86c82bfc125000025, nil]
138
+ Article.all # => all articles where tenant_id.in [50ca04b86c82bfc125000025, nil]
134
139
  article = Article.new(:title => 'New article')
135
- article.save # => <#Article _id: 50ca04b86c82bfc125000044, title: 'New blog', client_id: 50ca04b86c82bfc125000025>
140
+ article.save # => <#Article _id: 50ca04b86c82bfc125000044, title: 'New blog', tenant_id: 50ca04b86c82bfc125000025>
136
141
 
137
142
  # tenant needs to be set manually to nil
138
- article = Article.new(:title => 'New article', :client => nil)
139
- article.save # => <#Article _id: 50ca04b86c82bfc125000044, title: 'New blog', client_id: 50ca04b86c82bfc125000025>
143
+ article = Article.new(:title => 'New article', :tenant => nil)
144
+ article.save # => <#Article _id: 50ca04b86c82bfc125000044, title: 'New blog', tenant_id: 50ca04b86c82bfc125000025>
140
145
  article.tenant = nil
141
- article.save => <#Article _id: 50ca04b86c82bfc125000044, title: 'New blog', client_id: nil>
146
+ article.save => <#Article _id: 50ca04b86c82bfc125000044, title: 'New blog', tenant_id: nil>
142
147
  end
143
148
  ```
144
149
 
@@ -177,7 +182,7 @@ class Article
177
182
  include Mongoid::Document
178
183
  include Mongoid::Multitenancy::Document
179
184
 
180
- tenant :client
185
+ tenant :tenant
181
186
 
182
187
  field :slug
183
188
 
@@ -197,7 +202,7 @@ class Article
197
202
  include Mongoid::Document
198
203
  include Mongoid::Multitenancy::Document
199
204
 
200
- tenant :client, optional: true
205
+ tenant :tenant, optional: true
201
206
 
202
207
  field :slug
203
208
 
@@ -206,14 +211,14 @@ end
206
211
  ```
207
212
 
208
213
  In the following case, 2 private articles can have the same slug if they belongs to 2 different clients even if a shared
209
- article already uses that same slug, like a `validates_uniqueness_of scope: :client` does.
214
+ article already uses that same slug, like a `validates_uniqueness_of scope: :tenant` does.
210
215
 
211
216
  ```ruby
212
217
  class Article
213
218
  include Mongoid::Document
214
219
  include Mongoid::Multitenancy::Document
215
220
 
216
- tenant :client, optional: true
221
+ tenant :tenant, optional: true
217
222
 
218
223
  field :slug
219
224
 
@@ -230,14 +235,14 @@ To create a single index on the tenant field, you can use the option `index: tru
230
235
 
231
236
  On the example below, only one indexe will be created:
232
237
 
233
- * { 'title_id' => 1, 'client_id' => 1 }
238
+ * { 'title_id' => 1, 'tenant_id' => 1 }
234
239
 
235
240
  ```ruby
236
241
  class Article
237
242
  include Mongoid::Document
238
243
  include Mongoid::Multitenancy::Document
239
244
 
240
- tenant :client, full_indexes: true
245
+ tenant :tenant, full_indexes: true
241
246
 
242
247
  field :title
243
248
 
@@ -247,7 +252,7 @@ end
247
252
 
248
253
  On the example below, 2 indexes will be created:
249
254
 
250
- * { 'client_id' => 1 }
255
+ * { 'tenant_id' => 1 }
251
256
  * { 'title_id' => 1 }
252
257
 
253
258
  ```ruby
@@ -255,7 +260,7 @@ class Article
255
260
  include Mongoid::Document
256
261
  include Mongoid::Multitenancy::Document
257
262
 
258
- tenant :client, index: true
263
+ tenant :tenant, index: true
259
264
 
260
265
  field :title
261
266
 
@@ -109,6 +109,7 @@ module Mongoid
109
109
  options.each do |k, v|
110
110
  if MULTITENANCY_OPTIONS.include?(k)
111
111
  multitenant_options[k] = v
112
+ assoc_options[k] = v if k == :optional
112
113
  else
113
114
  assoc_options[k] = v
114
115
  end
@@ -39,14 +39,8 @@ module Mongoid
39
39
  criteria = with_tenant_criterion(criteria, klass, document)
40
40
  criteria = criteria.merge(options[:conditions].call) if options[:conditions]
41
41
 
42
- if Mongoid::VERSION.start_with?('4')
43
- if criteria.with(persistence_options(criteria)).exists?
44
- add_error(document, attribute, value)
45
- end
46
- else
47
- if criteria.with(criteria.persistence_options).read(mode: :primary).exists?
48
- add_error(document, attribute, value)
49
- end
42
+ if criteria.read(mode: :primary).exists?
43
+ add_error(document, attribute, value)
50
44
  end
51
45
  end
52
46
 
@@ -1,6 +1,6 @@
1
1
  module Mongoid
2
2
  module Multitenancy
3
3
  # Version
4
- VERSION = '1.2.0'.freeze
4
+ VERSION = '2.0'.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', '>= 4.0')
18
+ gem.add_dependency('mongoid', '~> 6.0')
19
19
  end
@@ -38,7 +38,7 @@ describe Immutable do
38
38
  end
39
39
 
40
40
  it 'is not valid' do
41
- item.client = another_client
41
+ item.tenant = another_client
42
42
  expect(item).not_to be_valid
43
43
  end
44
44
  end
@@ -11,25 +11,25 @@ describe 'tenant' do
11
11
 
12
12
  context 'without index: true' do
13
13
  it 'does not create an index' do
14
- expect(Immutable).not_to have_index_for(client_id: 1)
14
+ expect(Immutable).not_to have_index_for(tenant_id: 1)
15
15
  end
16
16
  end
17
17
 
18
18
  context 'with index: true' do
19
19
  it 'creates an index' do
20
- expect(Indexable).to have_index_for(client_id: 1)
20
+ expect(Indexable).to have_index_for(tenant_id: 1)
21
21
  end
22
22
  end
23
23
 
24
24
  context 'with full_indexes: true' do
25
25
  it 'add the tenant field on each index' do
26
- expect(Immutable).to have_index_for(client_id: 1, title: 1)
26
+ expect(Immutable).to have_index_for(tenant_id: 1, title: 1)
27
27
  end
28
28
  end
29
29
 
30
30
  context 'with full_indexes: false' do
31
31
  it 'does not add the tenant field on each index' do
32
- expect(Indexable).not_to have_index_for(client_id: 1, title: 1)
32
+ expect(Indexable).not_to have_index_for(tenant_id: 1, title: 1)
33
33
  end
34
34
  end
35
35
  end
@@ -2,7 +2,7 @@ class Immutable
2
2
  include Mongoid::Document
3
3
  include Mongoid::Multitenancy::Document
4
4
 
5
- tenant(:client, class_name: 'Account', immutable: true)
5
+ tenant(:tenant, class_name: 'Account', immutable: true)
6
6
 
7
7
  field :slug, type: String
8
8
  field :title, type: String
@@ -4,7 +4,7 @@ class Indexable
4
4
 
5
5
  field :title, type: String
6
6
 
7
- tenant :client, class_name: 'Account', index: true, full_indexes: false
7
+ tenant :tenant, class_name: 'Account', index: true, full_indexes: false
8
8
 
9
9
  index(title: 1)
10
10
  end
@@ -2,7 +2,7 @@ class Mandatory
2
2
  include Mongoid::Document
3
3
  include Mongoid::Multitenancy::Document
4
4
 
5
- tenant(:client, class_name: 'Account')
5
+ tenant(:tenant, class_name: 'Account')
6
6
 
7
7
  field :slug, type: String
8
8
  field :title, type: String
@@ -2,7 +2,7 @@ class Mutable
2
2
  include Mongoid::Document
3
3
  include Mongoid::Multitenancy::Document
4
4
 
5
- tenant :client, class_name: 'Account', immutable: false, optional: false
5
+ tenant :tenant, class_name: 'Account', immutable: false, optional: false
6
6
 
7
7
  field :slug, type: String
8
8
  field :title, type: String
@@ -2,7 +2,7 @@ class NoScopable
2
2
  include Mongoid::Document
3
3
  include Mongoid::Multitenancy::Document
4
4
 
5
- tenant :client, class_name: 'Account', scopes: false
5
+ tenant :tenant, class_name: 'Account', scopes: false
6
6
 
7
7
  field :slug, type: String
8
8
  field :title, type: String
@@ -2,7 +2,7 @@ class Optional
2
2
  include Mongoid::Document
3
3
  include Mongoid::Multitenancy::Document
4
4
 
5
- tenant(:client, class_name: 'Account', optional: true)
5
+ tenant(:tenant, class_name: 'Account', optional: true)
6
6
 
7
7
  field :slug, type: String
8
8
  field :title, type: String
@@ -2,7 +2,7 @@ class OptionalExclude
2
2
  include Mongoid::Document
3
3
  include Mongoid::Multitenancy::Document
4
4
 
5
- tenant(:client, class_name: 'Account', optional: true)
5
+ tenant(:tenant, class_name: 'Account', optional: true)
6
6
 
7
7
  field :slug, type: String
8
8
  field :title, type: String
@@ -38,7 +38,7 @@ describe MutableChild do
38
38
  end
39
39
 
40
40
  it 'is valid' do
41
- item.client = another_client
41
+ item.tenant = another_client
42
42
  expect(item).to be_valid
43
43
  end
44
44
  end
data/spec/mutable_spec.rb CHANGED
@@ -42,7 +42,7 @@ describe Mutable do
42
42
  end
43
43
 
44
44
  it 'is valid' do
45
- item.client = another_client
45
+ item.tenant = another_client
46
46
  expect(item).to be_valid
47
47
  end
48
48
  end
@@ -24,13 +24,13 @@ describe Optional do
24
24
 
25
25
  context 'when persisted' do
26
26
  before do
27
- item.client = nil
27
+ item.tenant = nil
28
28
  item.save!
29
29
  end
30
30
 
31
31
  it 'does not override the client' do
32
32
  item.reload
33
- expect(Optional.last.client).to be_nil
33
+ expect(Optional.last.tenant).to be_nil
34
34
  end
35
35
  end
36
36
  end
data/spec/spec_helper.rb CHANGED
@@ -30,7 +30,8 @@ Mongoid.configure do |config|
30
30
  config.connect_to 'mongoid_multitenancy'
31
31
  end
32
32
 
33
- Mongoid.logger = nil
33
+ Mongoid.logger.level = Logger::INFO
34
+ Mongo::Logger.logger.level = Logger::INFO
34
35
 
35
36
  RSpec.configure do |config|
36
37
  config.include Mongoid::Matchers
@@ -1,6 +1,6 @@
1
1
  shared_examples_for 'a tenantable model' do
2
- it { is_expected.to belong_to(:client) }
3
- it { is_expected.to have_index_for(client_id: 1, title: 1) }
2
+ it { is_expected.to belong_to(:tenant) }
3
+ it { is_expected.to have_index_for(tenant_id: 1, title: 1) }
4
4
 
5
5
  describe '#initialize' do
6
6
  context 'within a client context' do
@@ -9,7 +9,7 @@ shared_examples_for 'a tenantable model' do
9
9
  end
10
10
 
11
11
  it 'set the client' do
12
- expect(item.client).to eq client
12
+ expect(item.tenant).to eq client
13
13
  end
14
14
  end
15
15
 
@@ -19,7 +19,7 @@ shared_examples_for 'a tenantable model' do
19
19
  end
20
20
 
21
21
  it 'does not set any client' do
22
- expect(item.client).to be_nil
22
+ expect(item.tenant).to be_nil
23
23
  end
24
24
  end
25
25
  end
@@ -32,7 +32,7 @@ shared_examples_for 'a tenantable model' do
32
32
 
33
33
  context 'with the client id' do
34
34
  before do
35
- item.client = client
35
+ item.tenant = client
36
36
  end
37
37
 
38
38
  it 'is valid' do
@@ -42,7 +42,7 @@ shared_examples_for 'a tenantable model' do
42
42
 
43
43
  context 'with another client id' do
44
44
  before do
45
- item.client = another_client
45
+ item.tenant = another_client
46
46
  end
47
47
 
48
48
  it 'is not valid' do
@@ -58,7 +58,7 @@ shared_examples_for 'a tenantable model' do
58
58
 
59
59
  context 'with the client id' do
60
60
  before do
61
- item.client = client
61
+ item.tenant = client
62
62
  end
63
63
 
64
64
  it 'is valid' do
@@ -68,7 +68,7 @@ shared_examples_for 'a tenantable model' do
68
68
 
69
69
  context 'with another client id' do
70
70
  before do
71
- item.client = another_client
71
+ item.tenant = another_client
72
72
  end
73
73
 
74
74
  it 'is valid' do
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-multitenancy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aymeric Brisse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-30 00:00:00.000000000 Z
11
+ date: 2017-07-21 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
- version: '4.0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '6.0'
27
27
  description: MultiTenancy with Mongoid
28
28
  email:
29
29
  - aymeric.brisse@mperfect-memory.com
@@ -39,8 +39,6 @@ files:
39
39
  - LICENSE.TXT
40
40
  - README.md
41
41
  - Rakefile
42
- - gemfiles/Gemfile.mongoid-4.0
43
- - gemfiles/Gemfile.mongoid-5.0
44
42
  - lib/mongoid-multitenancy.rb
45
43
  - lib/mongoid/multitenancy.rb
46
44
  - lib/mongoid/multitenancy/document.rb
@@ -90,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
88
  version: '0'
91
89
  requirements: []
92
90
  rubyforge_project:
93
- rubygems_version: 2.4.5.1
91
+ rubygems_version: 2.6.11
94
92
  signing_key:
95
93
  specification_version: 4
96
94
  summary: Support of a multi-tenant database with Mongoid
@@ -117,4 +115,3 @@ test_files:
117
115
  - spec/spec_helper.rb
118
116
  - spec/support/mongoid_matchers.rb
119
117
  - spec/support/shared_examples.rb
120
- has_rdoc:
@@ -1,17 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'mongoid', '~> 4.0'
4
-
5
- gem 'rake', '~> 11.0'
6
-
7
- group :test do
8
- gem 'database_cleaner'
9
- gem 'coveralls', require: false
10
- gem 'rspec', '~> 3.1'
11
- gem 'yard', '~> 0.8'
12
- gem 'mongoid-rspec', '~> 2.1'
13
- gem 'rubocop', require: false
14
- end
15
-
16
- # Specify your gem's dependencies in mongoid-multitenancy.gemspec
17
- gemspec :path => '..'
@@ -1,17 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'mongoid', '~> 5.1'
4
-
5
- gem 'rake', '~> 11.0'
6
-
7
- group :test do
8
- gem 'database_cleaner'
9
- gem 'coveralls', require: false
10
- gem 'rspec', '~> 3.1'
11
- gem 'yard', '~> 0.8'
12
- gem 'mongoid-rspec', '~> 3.0'
13
- gem 'rubocop', require: false
14
- end
15
-
16
- # Specify your gem's dependencies in mongoid-multitenancy.gemspec
17
- gemspec :path => '..'