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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e167475943bea775b41d11e80881d5938607281e76076b5d0d847651a626f9ff
4
- data.tar.gz: 2bbf2defbe8dd5c2b7e05b65f74bc55db00ce39d02dee2ee99f5b23f4cd5eee5
3
+ metadata.gz: 528bb716891e71b4d2acde0199b4f92e7c386e3b6ef7236f13571d973cbb235a
4
+ data.tar.gz: 9bc59a8cec70d0914aea960d2248c6d3d024569a11d0873fa1920fb3318ea3bb
5
5
  SHA512:
6
- metadata.gz: 867f0dbe076cdf879d6e391bcce94e8bf4dd50a72afbec4a6dd0d386d1d245bf0f8fcd7b68b1e76b6eddd6340720d176a18781bf5afd2e4be58fbd87e02bbd0a
7
- data.tar.gz: cfb1c04cb18a416501752cb308174e2f4a3167d830701f36c9a76065574d308311206aad8c26a43d4bcb9fea8e326d565e850ebcda4931e1da5c2d8289c378b0
6
+ metadata.gz: 4e7e8bf18a8d5b0d327caac9c40149fe8dabcd450ecd3737446b96609b37083530ee972d542f31c87935dbae9745bc4ff0349861649a159da2b27ec4facf671c
7
+ data.tar.gz: dd9e26bbc1b954c47e2cb5250c87bce73866733214f0a73c876e3237eadf95b9e26052ac69ed457db5f559057a81726d873a9f86490ba0ecaf36a39394e14423
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.1 2019-08-27
4
+
5
+ * Ensure current tenant is present before adding tenant id filter in DatabaseStatements
6
+
3
7
 
4
8
  ## 1.0.0 2019-07-05
5
9
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-multi-tenant (1.0.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.3)
82
+ nokogiri (1.10.4)
83
83
  mini_portile2 (~> 2.4.0)
84
84
  pg (1.1.4)
85
85
  pry (0.12.2)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (1.0.0)
4
+ activerecord-multi-tenant (1.0.1)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (1.0.0)
4
+ activerecord-multi-tenant (1.0.1)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (1.0.0)
4
+ activerecord-multi-tenant (1.0.1)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (1.0.0)
4
+ activerecord-multi-tenant (1.0.1)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (1.0.0)
4
+ activerecord-multi-tenant (1.0.1)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (1.0.0)
4
+ activerecord-multi-tenant (1.0.1)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (1.0.0)
4
+ activerecord-multi-tenant (1.0.1)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (1.0.0)
4
+ activerecord-multi-tenant (1.0.1)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module MultiTenant
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -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.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-07-10 00:00:00.000000000 Z
11
+ date: 2019-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: request_store