activerecord-multi-tenant 1.0.0 → 1.0.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 +4 -0
- data/Gemfile.lock +2 -2
- data/gemfiles/active_record_5.1.gemfile.lock +1 -1
- data/gemfiles/active_record_5.2.gemfile.lock +1 -1
- data/gemfiles/rails_4.0.gemfile.lock +1 -1
- data/gemfiles/rails_4.1.gemfile.lock +1 -1
- data/gemfiles/rails_4.2.gemfile.lock +1 -1
- data/gemfiles/rails_5.0.gemfile.lock +1 -1
- data/gemfiles/rails_5.1.gemfile.lock +1 -1
- data/gemfiles/rails_5.2.gemfile.lock +1 -1
- data/lib/activerecord-multi-tenant/query_rewriter.rb +4 -4
- data/lib/activerecord-multi-tenant/version.rb +1 -1
- data/spec/activerecord-multi-tenant/query_rewriter_spec.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 528bb716891e71b4d2acde0199b4f92e7c386e3b6ef7236f13571d973cbb235a
|
4
|
+
data.tar.gz: 9bc59a8cec70d0914aea960d2248c6d3d024569a11d0873fa1920fb3318ea3bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e7e8bf18a8d5b0d327caac9c40149fe8dabcd450ecd3737446b96609b37083530ee972d542f31c87935dbae9745bc4ff0349861649a159da2b27ec4facf671c
|
7
|
+
data.tar.gz: dd9e26bbc1b954c47e2cb5250c87bce73866733214f0a73c876e3237eadf95b9e26052ac69ed457db5f559057a81726d873a9f86490ba0ecaf36a39394e14423
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
activerecord-multi-tenant (1.0.
|
4
|
+
activerecord-multi-tenant (1.0.1)
|
5
5
|
rails (>= 4.0)
|
6
6
|
request_store (>= 1.0.5)
|
7
7
|
|
@@ -79,7 +79,7 @@ GEM
|
|
79
79
|
mini_portile2 (2.4.0)
|
80
80
|
minitest (5.11.3)
|
81
81
|
nio4r (2.4.0)
|
82
|
-
nokogiri (1.10.
|
82
|
+
nokogiri (1.10.4)
|
83
83
|
mini_portile2 (~> 2.4.0)
|
84
84
|
pg (1.1.4)
|
85
85
|
pry (0.12.2)
|
@@ -223,7 +223,7 @@ module MultiTenant
|
|
223
223
|
def join_to_update(update, *args)
|
224
224
|
update = super(update, *args)
|
225
225
|
model = MultiTenant.multi_tenant_model_for_table(update.ast.relation.table_name)
|
226
|
-
if model.present? && !MultiTenant.with_write_only_mode_enabled?
|
226
|
+
if model.present? && !MultiTenant.with_write_only_mode_enabled? && MultiTenant.current_tenant_id.present?
|
227
227
|
update.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
|
228
228
|
end
|
229
229
|
update
|
@@ -232,7 +232,7 @@ module MultiTenant
|
|
232
232
|
def join_to_delete(delete, *args)
|
233
233
|
delete = super(delete, *args)
|
234
234
|
model = MultiTenant.multi_tenant_model_for_table(delete.ast.left.table_name)
|
235
|
-
if model.present? && !MultiTenant.with_write_only_mode_enabled?
|
235
|
+
if model.present? && !MultiTenant.with_write_only_mode_enabled? && MultiTenant.current_tenant_id.present?
|
236
236
|
delete.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
|
237
237
|
end
|
238
238
|
delete
|
@@ -241,7 +241,7 @@ module MultiTenant
|
|
241
241
|
if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2
|
242
242
|
def update(arel, name = nil, binds = [])
|
243
243
|
model = MultiTenant.multi_tenant_model_for_table(arel.ast.relation.table_name)
|
244
|
-
if model.present? && !MultiTenant.with_write_only_mode_enabled?
|
244
|
+
if model.present? && !MultiTenant.with_write_only_mode_enabled? && MultiTenant.current_tenant_id.present?
|
245
245
|
arel.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
|
246
246
|
end
|
247
247
|
super(arel, name, binds)
|
@@ -249,7 +249,7 @@ module MultiTenant
|
|
249
249
|
|
250
250
|
def delete(arel, name = nil, binds = [])
|
251
251
|
model = MultiTenant.multi_tenant_model_for_table(arel.ast.left.table_name)
|
252
|
-
if model.present? && !MultiTenant.with_write_only_mode_enabled?
|
252
|
+
if model.present? && !MultiTenant.with_write_only_mode_enabled? && MultiTenant.current_tenant_id.present?
|
253
253
|
arel.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
|
254
254
|
end
|
255
255
|
super(arel, name, binds)
|
@@ -15,6 +15,12 @@ describe "Query Rewriter" do
|
|
15
15
|
}.to change { project.reload.name }.from("Project 1").to("New Name")
|
16
16
|
end
|
17
17
|
|
18
|
+
it "updates the records without a current tenant" do
|
19
|
+
expect {
|
20
|
+
Project.joins(:manager).update_all(name: "New Name")
|
21
|
+
}.to change { project.reload.name }.from("Project 1").to("New Name")
|
22
|
+
end
|
23
|
+
|
18
24
|
it "update the record" do
|
19
25
|
expect {
|
20
26
|
MultiTenant.with(account) do
|
@@ -22,6 +28,12 @@ describe "Query Rewriter" do
|
|
22
28
|
end
|
23
29
|
}.to change { project.reload.name }.from("Project 1").to("New Name")
|
24
30
|
end
|
31
|
+
|
32
|
+
it "update the record without a current tenant" do
|
33
|
+
expect {
|
34
|
+
project.update(name: "New Name")
|
35
|
+
}.to change { project.reload.name }.from("Project 1").to("New Name")
|
36
|
+
end
|
25
37
|
end
|
26
38
|
|
27
39
|
context "when bulk deleting" do
|
@@ -40,6 +52,12 @@ describe "Query Rewriter" do
|
|
40
52
|
}.to change { Project.count }.from(3).to(1)
|
41
53
|
end
|
42
54
|
|
55
|
+
it "delete_all the records without a current tenant" do
|
56
|
+
expect {
|
57
|
+
Project.joins(:manager).delete_all
|
58
|
+
}.to change { Project.count }.from(3).to(1)
|
59
|
+
end
|
60
|
+
|
43
61
|
it "delete the record" do
|
44
62
|
expect {
|
45
63
|
MultiTenant.with(account) do
|
@@ -49,6 +67,13 @@ describe "Query Rewriter" do
|
|
49
67
|
}.to change { Project.count }.from(3).to(1)
|
50
68
|
end
|
51
69
|
|
70
|
+
it "delete the record without a current tenant" do
|
71
|
+
expect {
|
72
|
+
project1.delete
|
73
|
+
Project.delete(project2.id)
|
74
|
+
}.to change { Project.count }.from(3).to(1)
|
75
|
+
end
|
76
|
+
|
52
77
|
it "destroy the record" do
|
53
78
|
expect {
|
54
79
|
MultiTenant.with(account) do
|
@@ -57,5 +82,12 @@ describe "Query Rewriter" do
|
|
57
82
|
end
|
58
83
|
}.to change { Project.count }.from(3).to(1)
|
59
84
|
end
|
85
|
+
|
86
|
+
it "destroy the record without a current tenant" do
|
87
|
+
expect {
|
88
|
+
project1.destroy
|
89
|
+
Project.destroy(project2.id)
|
90
|
+
}.to change { Project.count }.from(3).to(1)
|
91
|
+
end
|
60
92
|
end
|
61
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-multi-tenant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Citus Data
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: request_store
|