activerecord-multi-tenant 2.1.4 → 2.1.5

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: eac7c3d60913d1596d061cdca9fca210c2f5e44eb87c60fe55a65f05161840fa
4
- data.tar.gz: b183e17a1effb9ad711e784a4ae82be5eb209b8b6d84993cfe4ea5db5c2fe800
3
+ metadata.gz: fb96e241668d1b08b01d087f2223f7ae703a73e09412f67aadb297aa0bb43818
4
+ data.tar.gz: f8e964e5549e489c93baaf0ce61b150eac3f3bb7c327dbec7994288c096a535c
5
5
  SHA512:
6
- metadata.gz: 3892fefdeb8636a7ceb80d5538cf49c73f7baf9957226f59156b8cfdceacd92760392aba0eee8232f17a9604eed1b502b9257c0df0614882e2d948afb64398ce
7
- data.tar.gz: b79eb29f19b1b5c2f3320fc3b79bc6fc8baa64a5217059a093e6fce77884280a9f9f67be2d1f842e620addfa61711704a63052c8b75c2ad3de68cd3c4e7a8407
6
+ metadata.gz: 5746bb54fb98adf017c0c888b6993a2e82fcca9a0f56588e405230bc1750c63723f89b9664b8f2d31dc11cbd43a1ee43a9d4e39f1ba784f4f9fc09450245833c
7
+ data.tar.gz: 448dda3c1b4406afe5aa602aa965bc5be35b18cbd539f8cd28fdd626ea00b65970d993fe6ae637ffeca3c809c43ab556ae2fdfdadcac853923b3222e798c6dc1
@@ -19,12 +19,10 @@ jobs:
19
19
  - '3.0'
20
20
  - '3.1'
21
21
  gemfile:
22
- - rails_5.2.3
23
22
  - rails_5.2
24
23
  - rails_6.0
25
24
  - rails_6.1
26
25
  - rails_7.0
27
- - active_record_5.2.3
28
26
  - active_record_5.2
29
27
  - active_record_6.0
30
28
  - active_record_6.1
@@ -49,14 +47,6 @@ jobs:
49
47
  gemfile: 'rails_5.2'
50
48
  - ruby: '3.1'
51
49
  gemfile: 'active_record_5.2'
52
- - ruby: '3.0'
53
- gemfile: 'rails_5.2.3'
54
- - ruby: '3.0'
55
- gemfile: 'active_record_5.2.3'
56
- - ruby: '3.1'
57
- gemfile: 'rails_5.2.3'
58
- - ruby: '3.1'
59
- gemfile: 'active_record_5.2.3'
60
50
  name: Ruby ${{ matrix.ruby }} / ${{ matrix.gemfile }} ${{ (matrix.prepared_statements && 'w/ prepared statements') || '' }}
61
51
  env:
62
52
  BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.5 2022-11-20
4
+ * Fix `MultiTenant.without` codegen bug in Rails 6.1+ [#168](https://github.com/citusdata/activerecord-multi-tenant/pull/168)
5
+
3
6
  ## 2.1.4 2022-11-03
4
7
  * Fixes #166 where db:schema:dump is broken when using this gem with MySQL [#167](https://github.com/citusdata/activerecord-multi-tenant/pull/167)
5
8
 
@@ -330,8 +330,9 @@ module ActiveRecord
330
330
  return nil, nil
331
331
  end
332
332
 
333
- if children[0].right.respond_to?('relation') && children[0].left.respond_to?('relation')
334
- return children[0].right.relation, children[0].left.relation
333
+ child = children.first.respond_to?(:children) ? children.first.children.first : children.first
334
+ if child.right.respond_to?(:relation) && child.left.respond_to?(:relation)
335
+ return child.right.relation, child.left.relation
335
336
  end
336
337
 
337
338
  return nil, nil
@@ -1,3 +1,3 @@
1
1
  module MultiTenant
2
- VERSION = '2.1.4'
2
+ VERSION = '2.1.5'
3
3
  end
@@ -299,6 +299,55 @@ describe MultiTenant do
299
299
  end
300
300
  end
301
301
 
302
+ # Joins
303
+ describe 'joins for models' do
304
+ context 'for models with where condition in associations' do
305
+ let(:account) { Account.create!(name: 'Account 1') }
306
+
307
+ it 'should add tenant condition to the queries when tenant is set' do
308
+ expected_join_sql = <<-SQL.strip
309
+ SELECT "comments".* FROM "comments" INNER JOIN "tasks" ON "tasks"."id" = "comments"."commentable_id" AND "comments"."commentable_type" = 'Task' AND "tasks"."account_id" = 1 WHERE "comments"."account_id" = 1
310
+ SQL
311
+
312
+ MultiTenant.with(account) do
313
+ expect(Comment.joins(:task).to_sql).to eq(expected_join_sql)
314
+ end
315
+ end
316
+
317
+ it 'should add tenant condition to the queries when tenant is not set' do
318
+ MultiTenant.without do
319
+ expected_join_sql = <<-SQL.strip
320
+ SELECT "comments".* FROM "comments" INNER JOIN "tasks" ON "tasks"."id" = "comments"."commentable_id" AND "comments"."commentable_type" = 'Task' AND "comments"."account_id" = "tasks"."account_id"
321
+ SQL
322
+ expect(Comment.joins(:task).to_sql).to eq(expected_join_sql)
323
+ end
324
+ end
325
+ end
326
+
327
+ context 'for models with default associations' do
328
+ let(:account) { Account.create!(name: 'Account 1') }
329
+
330
+ it 'should add tenant condition to the queries when tenant is set' do
331
+ expected_join_sql = <<-SQL.strip
332
+ SELECT "projects".* FROM "projects" INNER JOIN "tasks" ON "tasks"."project_id" = "projects"."id" AND "tasks"."account_id" = 1 WHERE "projects"."account_id" = 1
333
+ SQL
334
+
335
+ MultiTenant.with(account) do
336
+ expect(Project.joins(:tasks).to_sql).to eq(expected_join_sql)
337
+ end
338
+ end
339
+
340
+ it 'should add tenant condition to the queries when tenant is not set' do
341
+ MultiTenant.without do
342
+ expected_join_sql = <<-SQL.strip
343
+ SELECT "projects".* FROM "projects" INNER JOIN "tasks" ON "tasks"."project_id" = "projects"."id" AND "projects"."account_id" = "tasks"."account_id"
344
+ SQL
345
+ expect(Project.joins(:tasks).to_sql).to eq(expected_join_sql)
346
+ end
347
+ end
348
+ end
349
+ end
350
+
302
351
  # ::with
303
352
  describe "::with" do
304
353
  it "should set current_tenant to the specified tenant inside the block" do
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: 2.1.4
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Citus Data
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-03 00:00:00.000000000 Z
11
+ date: 2022-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -154,12 +154,10 @@ files:
154
154
  - activerecord-multi-tenant.gemspec
155
155
  - docker-compose.yml
156
156
  - gemfiles/.bundle/config
157
- - gemfiles/active_record_5.2.3.gemfile
158
157
  - gemfiles/active_record_5.2.gemfile
159
158
  - gemfiles/active_record_6.0.gemfile
160
159
  - gemfiles/active_record_6.1.gemfile
161
160
  - gemfiles/active_record_7.0.gemfile
162
- - gemfiles/rails_5.2.3.gemfile
163
161
  - gemfiles/rails_5.2.gemfile
164
162
  - gemfiles/rails_6.0.gemfile
165
163
  - gemfiles/rails_6.1.gemfile
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "activerecord", "~> 5.2.0", "< 5.2.4" # FIXME
7
- gem "i18n", "~> 0.9.5"
8
- gem "nokogiri", "~> 1.7.1"
9
- gem "nio4r", "~> 2.3.1"
10
- gem "sprockets", "~> 3.7.1"
11
- gem "byebug", "~> 11.0"
12
- gem "rake", "12.0.0"
13
- gem "redis", "3.3.3"
14
- gem "pry-byebug", "3.9.0"
15
-
16
- gemspec path: "../"
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rails", "~> 5.2.0", "< 5.2.4" # FIXME
7
- gem "i18n", "~> 0.9.5"
8
- gem "nokogiri", "~> 1.7.1"
9
- gem "nio4r", "~> 2.3.1"
10
- gem "sprockets", "~> 3.7.1"
11
- gem "byebug", "~> 11.0"
12
- gem "rake", "12.0.0"
13
- gem "redis", "3.3.3"
14
- gem "pry-byebug", "3.9.0"
15
-
16
- gemspec path: "../"