Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for latest rails 5.2 #145

Merged
merged 1 commit into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ jobs:
- '3.0'
- '3.1'
gemfile:
- rails_5.2.3
- rails_5.2
- rails_6.0
- rails_6.1
- rails_7.0
- active_record_5.2.3
- active_record_5.2
- active_record_6.0
- active_record_6.1
Expand All @@ -47,6 +49,14 @@ jobs:
gemfile: 'rails_5.2'
- ruby: '3.1'
gemfile: 'active_record_5.2'
- ruby: '3.0'
gemfile: 'rails_5.2.3'
- ruby: '3.0'
gemfile: 'active_record_5.2.3'
- ruby: '3.1'
gemfile: 'rails_5.2.3'
- ruby: '3.1'
gemfile: 'active_record_5.2.3'
name: Ruby ${{ matrix.ruby }} / ${{ matrix.gemfile }} ${{ (matrix.prepared_statements && 'w/ prepared statements') || '' }}
env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
Expand Down
16 changes: 16 additions & 0 deletions gemfiles/active_record_5.2.3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "activerecord", "~> 5.2.0", "< 5.2.4" # FIXME
gem "i18n", "~> 0.9.5"
gem "nokogiri", "~> 1.7.1"
gem "nio4r", "~> 2.3.1"
gem "sprockets", "~> 3.7.1"
gem "byebug", "~> 11.0"
gem "rake", "12.0.0"
gem "redis", "3.3.3"
gem "pry-byebug", "3.9.0"

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/active_record_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "https://rubygems.org"

gem "appraisal"
gem "activerecord", "~> 5.2.0", "< 5.2.4" # FIXME
gem "activerecord", "~> 5.2.0"
gem "i18n", "~> 0.9.5"
gem "nokogiri", "~> 1.7.1"
gem "nio4r", "~> 2.3.1"
Expand Down
16 changes: 16 additions & 0 deletions gemfiles/rails_5.2.3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "rails", "~> 5.2.0", "< 5.2.4" # FIXME
gem "i18n", "~> 0.9.5"
gem "nokogiri", "~> 1.7.1"
gem "nio4r", "~> 2.3.1"
gem "sprockets", "~> 3.7.1"
gem "byebug", "~> 11.0"
gem "rake", "12.0.0"
gem "redis", "3.3.3"
gem "pry-byebug", "3.9.0"

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "https://rubygems.org"

gem "appraisal"
gem "rails", "~> 5.2.0", "< 5.2.4" # FIXME
gem "rails", "~> 5.2.0"
gem "i18n", "~> 0.9.5"
gem "nokogiri", "~> 1.7.1"
gem "nio4r", "~> 2.3.1"
Expand Down
11 changes: 4 additions & 7 deletions lib/activerecord-multi-tenant/query_rewriter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,9 @@ def build_arel(*args)
end

node_list.select{ |n| n.is_a? Arel::Nodes::Join }.each do |node_join|
if (!node_join.right ||
(ActiveRecord::VERSION::MAJOR == 5 &&
!node_join.right.expr.right.is_a?(Arel::Attributes::Attribute)))
if !node_join.right
next
end

relation_right, relation_left = relations_from_node_join(node_join)

next unless relation_right && relation_left
Expand All @@ -322,13 +319,13 @@ def build_arel(*args)

private
def relations_from_node_join(node_join)
if ActiveRecord::VERSION::MAJOR == 5 || node_join.right.expr.is_a?(Arel::Nodes::Equality)
if node_join.right.expr.is_a?(Arel::Nodes::Equality)
return node_join.right.expr.right.relation, node_join.right.expr.left.relation
end

children = node_join.right.expr.children
children = [node_join.right.expr.children].flatten

tenant_applied = children.any?(MultiTenant::TenantEnforcementClause) || children.any?(MultiTenant::TenantJoinEnforcementClause)
tenant_applied = children.any?{|c| c.is_a?(MultiTenant::TenantEnforcementClause) || c.is_a?(MultiTenant::TenantJoinEnforcementClause)}
if tenant_applied || children.empty?
return nil, nil
end
Expand Down