activerecord-multi-tenant 2.1.4 → 2.1.6

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: 23f4082afb70ab964006573b094d2dd61a6aa0e015276504488d911578406f83
4
+ data.tar.gz: 509ebd9c590c472b84bba4d17ed9880f80d88e7fade20ec35350148634732cf6
5
5
  SHA512:
6
- metadata.gz: 3892fefdeb8636a7ceb80d5538cf49c73f7baf9957226f59156b8cfdceacd92760392aba0eee8232f17a9604eed1b502b9257c0df0614882e2d948afb64398ce
7
- data.tar.gz: b79eb29f19b1b5c2f3320fc3b79bc6fc8baa64a5217059a093e6fce77884280a9f9f67be2d1f842e620addfa61711704a63052c8b75c2ad3de68cd3c4e7a8407
6
+ metadata.gz: b359e5a9a001d1a20ad676fcf855eabe0dee36763245f779607942fe71ba937c8441fb944759790b3a07fb0dacb4cbff8bb329a17fac79de3468c7f1982c5b4b
7
+ data.tar.gz: cae89438df5db59a4e7cc9b804cfc73745c0ad1879dfcf0c21b2aee804e3657304cc8c36ebc301a5da371ad29d7e616adecd4440c36d55c5a6413b858e13abda
@@ -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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.6 2022-11-23
4
+ * Fix undefined wrap_methods error & wrap_methods version check [#170](https://github.com/citusdata/activerecord-multi-tenant/pull/170)
5
+
6
+ ## 2.1.5 2022-11-20
7
+ * Fix `MultiTenant.without` codegen bug in Rails 6.1+ [#168](https://github.com/citusdata/activerecord-multi-tenant/pull/168)
8
+
3
9
  ## 2.1.4 2022-11-03
4
10
  * 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
11
 
@@ -1,3 +1,5 @@
1
+ require_relative './multi_tenant'
2
+
1
3
  module MultiTenant
2
4
  module ModelExtensionsClassMethods
3
5
  DEFAULT_ID_FIELD = 'id'.freeze
@@ -110,7 +110,7 @@ module MultiTenant
110
110
  end
111
111
 
112
112
  # Wrap calls to any of `method_names` on an instance Class `klass` with MultiTenant.with when `'owner'` (evaluated in context of the klass instance) is a ActiveRecord model instance that is multi-tenant
113
- if Gem::Version.create(RUBY_VERSION) < Gem::Version.new("2.7.0")
113
+ if Gem::Version.create(RUBY_VERSION) < Gem::Version.new('3.0.0')
114
114
  def self.wrap_methods(klass, owner, *method_names)
115
115
  method_names.each do |method_name|
116
116
  original_method_name = :"_mt_original_#{method_name}"
@@ -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.6'
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.6
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-23 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: "../"