mongoid-multitenancy 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-multitenancy (0.3.2)
4
+ mongoid-multitenancy (0.3.3)
5
5
  mongoid (~> 3)
6
6
 
7
7
  GEM
@@ -7,6 +7,7 @@ module Mongoid
7
7
  attr_accessor :tenant_field
8
8
 
9
9
  def tenant(association = :account, options={})
10
+ original_options = options.clone
10
11
  tenant_options = { optional: options.delete(:optional), immutable: options.delete(:immutable) { true } }
11
12
  # Setup the association between the class and the tenant class
12
13
  # TODO: should index this association if no other indexes are defined => , index: true
@@ -40,6 +41,11 @@ module Mongoid
40
41
  where(nil)
41
42
  end
42
43
  }
44
+
45
+ self.define_singleton_method(:inherited) do |child|
46
+ child.tenant association, original_options
47
+ super(child)
48
+ end
43
49
  end
44
50
 
45
51
  # Redefine 'validates_with' to add the tenant scope when using a UniquenessValidator
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Multitenancy
3
- VERSION = "0.3.2"
3
+ VERSION = "0.3.3"
4
4
  end
5
5
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Inheritance' do
4
+
5
+ let(:client) { Account.create!(:name => "client") }
6
+
7
+ describe "class" do
8
+ before do
9
+ Mongoid::Multitenancy.current_tenant = client
10
+ MutableChild.create :title => "title X", :slug => "page-x"
11
+ end
12
+ after { Mongoid::Multitenancy.current_tenant = nil }
13
+
14
+ it 'should be valid' do
15
+ expect(Mutable.last).to be_a MutableChild
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ require 'models/mutable'
2
+
3
+ class MutableChild < Mutable
4
+
5
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe MutableChild do
4
+
5
+ let(:client) { Account.create!(:name => "client") }
6
+ let(:another_client) { Account.create!(:name => "another client") }
7
+
8
+ describe "#valid?" do
9
+ before { Mongoid::Multitenancy.current_tenant = client; }
10
+ after { Mongoid::Multitenancy.current_tenant = nil }
11
+
12
+ let(:item) { MutableChild.new(:title => "title X", :slug => "page-x") }
13
+
14
+ it_behaves_like "a tenant validator"
15
+
16
+ context "when the tenant has not changed" do
17
+ before { item.save! }
18
+ it 'should be valid' do
19
+ item.title = "title X (2)"
20
+ item.should be_valid
21
+ end
22
+ end
23
+
24
+ context "when the tenant has changed" do
25
+ before { item.save!; Mongoid::Multitenancy.current_tenant = another_client }
26
+ it 'should be valid' do
27
+ item.client = another_client
28
+ item.should be_valid
29
+ end
30
+ end
31
+ end
32
+
33
+ end
metadata CHANGED
@@ -1,113 +1,128 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-multitenancy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ prerelease:
5
+ version: 0.3.3
5
6
  platform: ruby
6
7
  authors:
7
8
  - Aymeric Brisse
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-06-03 00:00:00.000000000 Z
12
+ date: 2013-09-24 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
15
+ prerelease: false
14
16
  name: mongoid
17
+ type: :runtime
15
18
  requirement: !ruby/object:Gem::Requirement
16
19
  requirements:
17
20
  - - ~>
18
21
  - !ruby/object:Gem::Version
19
22
  version: '3'
20
- type: :runtime
21
- prerelease: false
23
+ none: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
26
  - - ~>
25
27
  - !ruby/object:Gem::Version
26
28
  version: '3'
29
+ none: false
27
30
  - !ruby/object:Gem::Dependency
31
+ prerelease: false
28
32
  name: rake
33
+ type: :development
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
36
  - - ~>
32
37
  - !ruby/object:Gem::Version
33
38
  version: '10.0'
34
- type: :development
35
- prerelease: false
39
+ none: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
37
41
  requirements:
38
42
  - - ~>
39
43
  - !ruby/object:Gem::Version
40
44
  version: '10.0'
45
+ none: false
41
46
  - !ruby/object:Gem::Dependency
47
+ prerelease: false
42
48
  name: rspec
49
+ type: :development
43
50
  requirement: !ruby/object:Gem::Requirement
44
51
  requirements:
45
52
  - - ~>
46
53
  - !ruby/object:Gem::Version
47
54
  version: '2.12'
48
- type: :development
49
- prerelease: false
55
+ none: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - ~>
53
59
  - !ruby/object:Gem::Version
54
60
  version: '2.12'
61
+ none: false
55
62
  - !ruby/object:Gem::Dependency
63
+ prerelease: false
56
64
  name: yard
65
+ type: :development
57
66
  requirement: !ruby/object:Gem::Requirement
58
67
  requirements:
59
68
  - - ~>
60
69
  - !ruby/object:Gem::Version
61
70
  version: '0.8'
62
- type: :development
63
- prerelease: false
71
+ none: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
65
73
  requirements:
66
74
  - - ~>
67
75
  - !ruby/object:Gem::Version
68
76
  version: '0.8'
77
+ none: false
69
78
  - !ruby/object:Gem::Dependency
79
+ prerelease: false
70
80
  name: mongoid-rspec
81
+ type: :development
71
82
  requirement: !ruby/object:Gem::Requirement
72
83
  requirements:
73
84
  - - ~>
74
85
  - !ruby/object:Gem::Version
75
86
  version: '1.5'
76
- type: :development
77
- prerelease: false
87
+ none: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
79
89
  requirements:
80
90
  - - ~>
81
91
  - !ruby/object:Gem::Version
82
92
  version: '1.5'
93
+ none: false
83
94
  - !ruby/object:Gem::Dependency
95
+ prerelease: false
84
96
  name: database_cleaner
97
+ type: :development
85
98
  requirement: !ruby/object:Gem::Requirement
86
99
  requirements:
87
100
  - - ~>
88
101
  - !ruby/object:Gem::Version
89
102
  version: '1.0'
90
- type: :development
91
- prerelease: false
103
+ none: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
93
105
  requirements:
94
106
  - - ~>
95
107
  - !ruby/object:Gem::Version
96
108
  version: '1.0'
109
+ none: false
97
110
  - !ruby/object:Gem::Dependency
111
+ prerelease: false
98
112
  name: redcarpet
113
+ type: :development
99
114
  requirement: !ruby/object:Gem::Requirement
100
115
  requirements:
101
116
  - - ~>
102
117
  - !ruby/object:Gem::Version
103
118
  version: '2.2'
104
- type: :development
105
- prerelease: false
119
+ none: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ~>
109
123
  - !ruby/object:Gem::Version
110
124
  version: '2.2'
125
+ none: false
111
126
  description: MultiTenancy with Mongoid
112
127
  email:
113
128
  - aymeric.brisse@mperfect-memory.com
@@ -129,19 +144,21 @@ files:
129
144
  - lib/mongoid/validators/tenant_validator.rb
130
145
  - mongoid-multitenancy.gemspec
131
146
  - spec/immutable_spec.rb
147
+ - spec/inheritance_spec.rb
132
148
  - spec/mandatory_spec.rb
133
149
  - spec/models/account.rb
134
150
  - spec/models/immutable.rb
135
151
  - spec/models/mandatory.rb
136
152
  - spec/models/mutable.rb
153
+ - spec/models/mutable_child.rb
137
154
  - spec/models/optional.rb
138
155
  - spec/mongoid-multitenancy_spec.rb
156
+ - spec/mutable_child_spec.rb
139
157
  - spec/mutable_spec.rb
140
158
  - spec/optional_spec.rb
141
159
  - spec/spec_helper.rb
142
160
  homepage: https://github.com/PerfectMemory/mongoid-multitenancy
143
161
  licenses: []
144
- metadata: {}
145
162
  post_install_message:
146
163
  rdoc_options: []
147
164
  require_paths:
@@ -150,27 +167,38 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
167
  requirements:
151
168
  - - ! '>='
152
169
  - !ruby/object:Gem::Version
170
+ segments:
171
+ - 0
172
+ hash: 3855106664827069335
153
173
  version: '0'
174
+ none: false
154
175
  required_rubygems_version: !ruby/object:Gem::Requirement
155
176
  requirements:
156
177
  - - ! '>='
157
178
  - !ruby/object:Gem::Version
179
+ segments:
180
+ - 0
181
+ hash: 3855106664827069335
158
182
  version: '0'
183
+ none: false
159
184
  requirements: []
160
185
  rubyforge_project:
161
- rubygems_version: 2.0.1
186
+ rubygems_version: 1.8.25
162
187
  signing_key:
163
- specification_version: 4
188
+ specification_version: 3
164
189
  summary: Support of a multi-tenant database with Mongoid
165
190
  test_files:
166
191
  - spec/immutable_spec.rb
192
+ - spec/inheritance_spec.rb
167
193
  - spec/mandatory_spec.rb
168
194
  - spec/models/account.rb
169
195
  - spec/models/immutable.rb
170
196
  - spec/models/mandatory.rb
171
197
  - spec/models/mutable.rb
198
+ - spec/models/mutable_child.rb
172
199
  - spec/models/optional.rb
173
200
  - spec/mongoid-multitenancy_spec.rb
201
+ - spec/mutable_child_spec.rb
174
202
  - spec/mutable_spec.rb
175
203
  - spec/optional_spec.rb
176
204
  - spec/spec_helper.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZWQ3NzVkNzFkZGVlMDc3Y2Y5NTc1ZjI0MDhkNjA0YWRhNDIxMzMzNA==
5
- data.tar.gz: !binary |-
6
- ZDMzNmQyMmFmZmEyYTYwYWM5ZjA3NGI0NzkxOGI1MGIxYTU0NGM2OA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YjJkOGZlZDVkODlhODE3ZWUwYzM2NjliZmRhNjRhMDYxYWI3NWJiZDE5YWU3
10
- YWQ3ODg1OWUwNzRmYTg2OWMyMDA2OTY2MmNlZGE1Y2JkNWExNTM1NjI4YTc0
11
- NWYwZGE3MmE2OGYxMzNhZWNkMjI2YzE0ZmE2NGMyNzAzMmZiYTg=
12
- data.tar.gz: !binary |-
13
- YTBlZjk0OGFmM2Q4YjZhYjYyNjc3MTY0MmNiYTBjZjgxODNjM2Y3ZDA1NzMx
14
- YmQ4MDkxOGU4MTgyMWM5ZWRiYThkMTUxMGJkYmQxOTY0OTYwMGM2ZWE3YTAy
15
- ZDFmYzg3Y2FjOTAxMDZkZWMwNTg1NjExOWY5NjFlZjc2NzJmNDg=