rails_multitenant 0.7.0 → 0.7.1
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 +9 -0
- data/lib/rails_multitenant/version.rb +1 -1
- data/spec/item_spec.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4332139531ab7372309d2b3452fdc0d19ebee747
|
4
|
+
data.tar.gz: ea6ec3f22079f4f7ba1049bae89e863c41372d18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaca7f0b01574daef246942acffbc94a36a00b3369d1e7b27f2899b4ed051d3a8a3c750656eefa64a3407a173b8f977cc69db637f28817599c795935f885e34d
|
7
|
+
data.tar.gz: 7adfb31a0b8a54e5e020a169c3410d8d8a0f3aae1cd5f393769dde2699bbf77ce1e4f105670365765973f89c7c7d7040e962991af607f5bfaa69a78300a4354c
|
data/CHANGELOG.md
CHANGED
@@ -60,6 +60,7 @@ module RailsMultitenant
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def current=(object)
|
63
|
+
raise "#{object} is not a #{self}" if object.present? && !object.is_a?(self)
|
63
64
|
GlobalContextRegistry.set(current_instance_registry_obj, object)
|
64
65
|
GlobalContextRegistry.set(current_instance_registry_id, object.try(:id))
|
65
66
|
__clear_dependents!
|
@@ -91,6 +92,14 @@ module RailsMultitenant
|
|
91
92
|
self.current_id = old_id
|
92
93
|
end
|
93
94
|
|
95
|
+
def as_current(model)
|
96
|
+
old_model = current
|
97
|
+
self.current = model
|
98
|
+
yield
|
99
|
+
ensure
|
100
|
+
self.current = old_model
|
101
|
+
end
|
102
|
+
|
94
103
|
def clear_current!
|
95
104
|
GlobalContextRegistry.delete(current_instance_registry_obj)
|
96
105
|
end
|
data/spec/item_spec.rb
CHANGED
@@ -30,4 +30,23 @@ describe Item do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
describe '.as_current' do
|
34
|
+
it 'returns the correct items with an org supplied' do
|
35
|
+
Organization.as_current(org2) do
|
36
|
+
expect(Item.all).to eq [ item2, item3]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'allows a nil org to be supplied' do
|
41
|
+
Organization.as_current(nil) do
|
42
|
+
expect(Item.all).to eq []
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'rejects models of the wrong type' do
|
47
|
+
model = Item.new
|
48
|
+
expect { Organization.as_current(model) {}}.to raise_error("#{model} is not a Organization")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
33
52
|
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.1
|
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
|
+
date: 2017-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|