rails_multitenant 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/rails_multitenant/global_context_registry.rb +2 -1
- data/lib/rails_multitenant/version.rb +1 -1
- data/spec/current_spec.rb.dis +80 -0
- data/spec/db/schema.rb +7 -0
- data/spec/item_spec.rb +26 -0
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77e1e600d2a712b57994c01909b43921dfbab522
|
4
|
+
data.tar.gz: c8ce8ec444923042f9035984bc6247a10f15a0f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa5c9360a04697ff2d7732f7d80cc11fa0696cfc5a40ff12b769ce92227dc15a2c2c3451a719c0c1dc55ad2a35dc63179587ab35e8c3901a835a04f1d756c49b
|
7
|
+
data.tar.gz: 7462b3c8d160c56516e5a17d07f17bf6baaaa29c26766d583faff24cef4289b9fddd20a0e5ba393329ac8004079bc23bf3c5892e5b8dd275e025e9ee549511c6
|
data/CHANGELOG.md
CHANGED
@@ -107,7 +107,8 @@ module RailsMultitenant
|
|
107
107
|
private
|
108
108
|
|
109
109
|
def __clear_dependents!
|
110
|
-
|
110
|
+
key_class = respond_to?(:base_class) ? base_class : self
|
111
|
+
GlobalContextRegistry.send(:dependencies_for, key_class).each(&:clear_current!)
|
111
112
|
end
|
112
113
|
|
113
114
|
def current_instance_registry_id
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# Create multiple orgs
|
2
|
+
# Create an item in each
|
3
|
+
# Make sure you can only see one org's item in one org
|
4
|
+
|
5
|
+
describe RailsMultitenant::GlobalContextRegistry::Current do
|
6
|
+
|
7
|
+
class Parent
|
8
|
+
include RailsMultitenant::GlobalContextRegistry::Current
|
9
|
+
|
10
|
+
attr_accessor :id
|
11
|
+
|
12
|
+
def initialize(id: 0)
|
13
|
+
@id = id
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Dependent
|
18
|
+
include RailsMultitenant::GlobalContextRegistry::Current
|
19
|
+
global_context_dependent_on Parent
|
20
|
+
end
|
21
|
+
|
22
|
+
class StepParent < Parent
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'current' do
|
26
|
+
expect(Parent.current.id).to eq(0)
|
27
|
+
expect(Parent.current).to eq(Parent.current)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'current=' do
|
31
|
+
Parent.current = Parent.new(id: 42)
|
32
|
+
expect(Parent.current.id).to eq(42)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
it 'clear_current!' do
|
37
|
+
Parent.clear_current!
|
38
|
+
expect(Parent.current.id).to eq(0)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'current?' do
|
42
|
+
Parent.clear_current!
|
43
|
+
expect(Parent.current?).to be_falsey
|
44
|
+
Parent.current = Parent.new(id: 42)
|
45
|
+
expect(Parent.current?).to be_truthy
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with dependencies' do
|
49
|
+
it 'dependent is cleared' do
|
50
|
+
Parent.current = Parent.new(id: 78)
|
51
|
+
Dependent.current = Dependent.new
|
52
|
+
Parent.current = Parent.new(id: 78)
|
53
|
+
expect(Dependent.current?).to be_falsey
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'dependent subclass is cleared' do
|
57
|
+
Parent.current = Parent.new(id: 78)
|
58
|
+
Dependent.current = Dependent.new
|
59
|
+
Parent.current = StepParent.new(id: 78)
|
60
|
+
expect(Dependent.current?).to be_falsey
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
#let(dependent_id) { Organization.current.id }
|
65
|
+
|
66
|
+
it 'dependent model subclass is cleared' do
|
67
|
+
#Organization.current = Organization.create!
|
68
|
+
DependsOnOrganization.current = DependsOnOrganization.create!
|
69
|
+
dependent_id = DependsOnOrganization.current.object_id
|
70
|
+
SubOrganization.current = SubOrganization.create!
|
71
|
+
expect(DependsOnOrganization.current.object_id).not_to eq(dependent_id)
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/spec/db/schema.rb
CHANGED
@@ -4,6 +4,8 @@ ActiveRecord::Schema.define(version: 0) do
|
|
4
4
|
|
5
5
|
create_table(:organizations, force: true)
|
6
6
|
|
7
|
+
create_table(:dependent_models, force: true)
|
8
|
+
|
7
9
|
create_table(:items, force: true) do |t|
|
8
10
|
t.integer :organization_id
|
9
11
|
t.string :type
|
@@ -27,6 +29,11 @@ class Organization < ActiveRecord::Base
|
|
27
29
|
include RailsMultitenant::GlobalContextRegistry::CurrentInstance
|
28
30
|
end
|
29
31
|
|
32
|
+
class DependentModel < ActiveRecord::Base
|
33
|
+
include RailsMultitenant::GlobalContextRegistry::CurrentInstance
|
34
|
+
global_context_dependent_on Organization
|
35
|
+
end
|
36
|
+
|
30
37
|
class Item < ActiveRecord::Base
|
31
38
|
include RailsMultitenant::MultitenantModel
|
32
39
|
multitenant_on_model :organization
|
data/spec/item_spec.rb
CHANGED
@@ -30,6 +30,15 @@ describe Item do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
class DependentClass
|
34
|
+
include RailsMultitenant::GlobalContextRegistry::Current
|
35
|
+
global_context_dependent_on Organization
|
36
|
+
end
|
37
|
+
|
38
|
+
class SubOrganization < Organization
|
39
|
+
|
40
|
+
end
|
41
|
+
|
33
42
|
describe '.as_current' do
|
34
43
|
it 'returns the correct items with an org supplied' do
|
35
44
|
Organization.as_current(org2) do
|
@@ -47,6 +56,23 @@ describe Item do
|
|
47
56
|
model = Item.new
|
48
57
|
expect { Organization.as_current(model) {}}.to raise_error("#{model} is not a Organization")
|
49
58
|
end
|
59
|
+
|
60
|
+
it 'invalidates dependent models' do
|
61
|
+
DependentModel.current = DependentModel.create!
|
62
|
+
dependent = DependentModel.current
|
63
|
+
|
64
|
+
SubOrganization.create!.as_current do
|
65
|
+
expect(DependentModel.current).not_to equal(dependent)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'invalidates dependent objects' do
|
70
|
+
dependent = DependentClass.current
|
71
|
+
|
72
|
+
SubOrganization.create!.as_current do
|
73
|
+
expect(DependentClass.current).not_to equal(dependent)
|
74
|
+
end
|
75
|
+
end
|
50
76
|
end
|
51
77
|
|
52
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_multitenant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Breault
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -176,6 +176,7 @@ files:
|
|
176
176
|
- lib/rails_multitenant/version.rb
|
177
177
|
- rails_multitenant.gemspec
|
178
178
|
- spec/be_multitenant_on_matcher_spec.rb
|
179
|
+
- spec/current_spec.rb.dis
|
179
180
|
- spec/db/database.yml
|
180
181
|
- spec/db/schema.rb
|
181
182
|
- spec/external_item_spec.rb
|
@@ -211,14 +212,15 @@ signing_key:
|
|
211
212
|
specification_version: 4
|
212
213
|
summary: Automatically configures multiple tenants in a Rails environment
|
213
214
|
test_files:
|
214
|
-
- spec/
|
215
|
-
- spec/db/database.yml
|
216
|
-
- spec/db/schema.rb
|
217
|
-
- spec/external_item_spec.rb
|
218
|
-
- spec/external_item_with_optional_org_spec.rb
|
215
|
+
- spec/spec_helper.rb
|
219
216
|
- spec/global_context_registry_spec.rb
|
220
|
-
- spec/
|
217
|
+
- spec/external_item_spec.rb
|
221
218
|
- spec/item_subtype_spec.rb
|
219
|
+
- spec/current_spec.rb.dis
|
220
|
+
- spec/item_spec.rb
|
221
|
+
- spec/external_item_with_optional_org_spec.rb
|
222
|
+
- spec/db/schema.rb
|
223
|
+
- spec/db/database.yml
|
224
|
+
- spec/be_multitenant_on_matcher_spec.rb
|
222
225
|
- spec/item_with_optional_org_spec.rb
|
223
226
|
- spec/middleware_isolated_context_registry_spec.rb
|
224
|
-
- spec/spec_helper.rb
|