mongoid-multitenancy 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e24dad42cdd8d6692c7c37ae3d370c11615423ed
4
- data.tar.gz: 0a6b110bab9bd521fe3be96a76cc7f10e9ef4957
3
+ metadata.gz: 046b1e5327369856dee33f99a53977a2193dfc78
4
+ data.tar.gz: 696c53ac82dc8c0580c365379055dcd02bfa64ae
5
5
  SHA512:
6
- metadata.gz: 5ffaa31b8280e405b4b0e7acd7b5ad84e8c15ae3815be55a962526ef6cf9d918ea76d144041856d0f281153e31dbea025bdf5cee6ab0d1546436751022fa777c
7
- data.tar.gz: 68fa75bceb0e1103a0307edafb1e0b2d4110bb1f76473b13a823d560dd35e5ca00a8bbc2c94413fcb358d77eb24e608cc9bdf8efe36139b8347051188cca5ecf
6
+ metadata.gz: bf99d6fd58f15a2f12caf85c37a9b621cace5146958c39c34a6df286285dcdbb302664970781f494d6a0761d638a7662cf9a40ccb6413813ccf48002e9238f41
7
+ data.tar.gz: a8ba34aa544fb199f7f45335224d29e4c3bb90967f0f8240fd0069d0be820c6ae24bb075a5c71aa25a2ba95ab8978386f089b8538076a10435ab0bf5ebe33722
@@ -36,8 +36,7 @@ module Mongoid
36
36
  criteria = create_criteria(klass, document, attribute, value)
37
37
 
38
38
  # <<Add the tenant Criteria>>
39
- add_tenant_criterion(criteria, klass, document)
40
-
39
+ criteria = with_tenant_criterion(criteria, klass, document)
41
40
  criteria = criteria.merge(options[:conditions].call) if options[:conditions]
42
41
 
43
42
  if Mongoid::VERSION.start_with?('4')
@@ -51,18 +50,19 @@ module Mongoid
51
50
  end
52
51
  end
53
52
 
54
- # Create the validation criteria for a tenant model.
53
+ # Add the scope criteria for a tenant model criteria.
55
54
  #
56
55
  # @api private
57
- def add_tenant_criterion(criteria, base, document)
58
- tenant_value = document.send(base.tenant_field.to_sym)
56
+ def with_tenant_criterion(criteria, base, document)
57
+ item = base.tenant_field.to_sym
58
+ name = document.database_field_name(item)
59
59
 
60
60
  if document.class.tenant_options[:optional]
61
- if tenant_value
62
- criteria.selector.update(criterion(document, base.tenant_field, {'$in' => [tenant_value, nil].mongoize}))
61
+ if tenant_value = document.attributes[name]
62
+ criteria = criteria.where(:"#{item}".in => [tenant_value, nil])
63
63
  end
64
64
  else
65
- criteria.selector.update(criterion(document, base.tenant_field, tenant_value.mongoize))
65
+ criteria = criteria.where(item => tenant_value)
66
66
  end
67
67
 
68
68
  criteria
@@ -1,6 +1,6 @@
1
1
  module Mongoid
2
2
  module Multitenancy
3
3
  # Version
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
6
6
  end
@@ -155,7 +155,7 @@ describe Optional do
155
155
  describe '#valid?' do
156
156
  context 'with a tenant' do
157
157
  before do
158
- item.client = client
158
+ Mongoid::Multitenancy.current_tenant = client
159
159
  end
160
160
 
161
161
  it 'is valid' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-multitenancy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aymeric Brisse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  requirements: []
89
89
  rubyforge_project:
90
- rubygems_version: 2.4.6
90
+ rubygems_version: 2.2.5
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Support of a multi-tenant database with Mongoid