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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4332139531ab7372309d2b3452fdc0d19ebee747
4
- data.tar.gz: ea6ec3f22079f4f7ba1049bae89e863c41372d18
3
+ metadata.gz: 77e1e600d2a712b57994c01909b43921dfbab522
4
+ data.tar.gz: c8ce8ec444923042f9035984bc6247a10f15a0f1
5
5
  SHA512:
6
- metadata.gz: aaca7f0b01574daef246942acffbc94a36a00b3369d1e7b27f2899b4ed051d3a8a3c750656eefa64a3407a173b8f977cc69db637f28817599c795935f885e34d
7
- data.tar.gz: 7adfb31a0b8a54e5e020a169c3410d8d8a0f3aae1cd5f393769dde2699bbf77ce1e4f105670365765973f89c7c7d7040e962991af607f5bfaa69a78300a4354c
6
+ metadata.gz: aa5c9360a04697ff2d7732f7d80cc11fa0696cfc5a40ff12b769ce92227dc15a2c2c3451a719c0c1dc55ad2a35dc63179587ab35e8c3901a835a04f1d756c49b
7
+ data.tar.gz: 7462b3c8d160c56516e5a17d07f17bf6baaaa29c26766d583faff24cef4289b9fddd20a0e5ba393329ac8004079bc23bf3c5892e5b8dd275e025e9ee549511c6
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.7.2
4
+ * Fix bug that prevents clearing dependents of classes derived from CurrentInstance.
5
+
3
6
  ### 0.7.1
4
7
  * Added as_current multi-tenant class method.
5
8
 
@@ -107,7 +107,8 @@ module RailsMultitenant
107
107
  private
108
108
 
109
109
  def __clear_dependents!
110
- GlobalContextRegistry.send(:dependencies_for, self).each(&:clear_current!)
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
@@ -1,3 +1,3 @@
1
1
  module RailsMultitenant
2
- VERSION = '0.7.1'
2
+ VERSION = '0.7.2'
3
3
  end
@@ -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
@@ -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
@@ -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.1
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: 2017-11-28 00:00:00.000000000 Z
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/be_multitenant_on_matcher_spec.rb
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/item_spec.rb
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