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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '08f671a9e38be41cc1e23a8f79db4f7d8b2b5a09'
4
- data.tar.gz: c59f436adebc42b31b325df61f5c74a2227855d4
3
+ metadata.gz: 4332139531ab7372309d2b3452fdc0d19ebee747
4
+ data.tar.gz: ea6ec3f22079f4f7ba1049bae89e863c41372d18
5
5
  SHA512:
6
- metadata.gz: c0c279650d661914c08bf934a70d6b8cf8043feeb233be653d2721a4fcb3f58cc37632818195ab16fa8dba75b2e45f2587c24698c459f01791b368d212bed7ef
7
- data.tar.gz: 90e7b9c505b892fa5f8673c51c1556dbe8c6741dbf6f74b994c5b57ce0f23f61fa752ef3fdbd2104122b63d2bf3cd4a5845ac665aafa894b20425c70f1c16ee9
6
+ metadata.gz: aaca7f0b01574daef246942acffbc94a36a00b3369d1e7b27f2899b4ed051d3a8a3c750656eefa64a3407a173b8f977cc69db637f28817599c795935f885e34d
7
+ data.tar.gz: 7adfb31a0b8a54e5e020a169c3410d8d8a0f3aae1cd5f393769dde2699bbf77ce1e4f105670365765973f89c7c7d7040e962991af607f5bfaa69a78300a4354c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.7.1
4
+ * Added as_current multi-tenant class method.
5
+
3
6
  ### 0.7.0
4
7
  * Add Rack middleware to create a new isolated registry per request.
5
8
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RailsMultitenant
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
3
3
  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.0
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-10-06 00:00:00.000000000 Z
11
+ date: 2017-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler