Skip to content

Commit

Permalink
Rails 7.1/7.2 (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
jprosevear authored Sep 10, 2024
1 parent c1e0763 commit 024f6c7
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 13 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ name: Unit Tests
on:
pull_request:
branches:
- '*'
- "*"
push:
branches:
- '*'
- "master"
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- gemfile: gemfiles/rails_3.1.x.gemfile
ruby-version: 2.2
- gemfile: gemfiles/rails_3.2.x.gemfile
ruby-version: 2.2
- gemfile: gemfiles/rails_4.0.x.gemfile
ruby-version: 2.3
- gemfile: gemfiles/rails_4.1.x.gemfile
Expand All @@ -38,8 +34,14 @@ jobs:
ruby-version: 3.0
- gemfile: gemfiles/rails_7.0.x.gemfile
ruby-version: 3.0
- gemfile: gemfiles/rails_7.1.x.gemfile
ruby-version: 3.1
- gemfile: gemfiles/rails_7.1.x.gemfile
ruby-version: 3.2
- gemfile: gemfiles/rails_7.2.x.gemfile
ruby-version: 3.3
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion arel-helpers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |s|

s.add_development_dependency 'appraisal'
s.add_development_dependency 'combustion', '~> 1.3'
s.add_development_dependency 'database_cleaner', '~> 1.8'
s.add_development_dependency 'database_cleaner', '~> 2.0'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '~> 3'
s.add_development_dependency 'sqlite3', '~> 1.4.0'
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_4.0.x.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ source "https://rubygems.org"

gem "activerecord", "~> 4.0.0"
gem "sqlite3", "~> 1.3.0"
gem "database_cleaner", "~> 1.8.0"

gemspec path: "../"
1 change: 1 addition & 0 deletions gemfiles/rails_4.1.x.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ source "https://rubygems.org"

gem "activerecord", "~> 4.1.0"
gem "sqlite3", "~> 1.3.0"
gem "database_cleaner", "~> 1.8.0"

gemspec path: "../"
1 change: 1 addition & 0 deletions gemfiles/rails_4.2.x.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ source "https://rubygems.org"

gem "activerecord", "~> 4.2.0"
gem "sqlite3", "~> 1.3.0"
gem "database_cleaner", "~> 1.8.0"

gemspec path: "../"
1 change: 1 addition & 0 deletions gemfiles/rails_5.0.x.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ source "https://rubygems.org"

gem "activerecord", "~> 5.0.0"
gem "sqlite3", "~> 1.3.0"
gem "database_cleaner", "~> 1.8.0"

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

source "https://rubygems.org"

gem "activerecord", "~> 3.1.0"
gem "sqlite3", "~> 1.3.0"
gem "activerecord", "~> 7.1.0"

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

source "https://rubygems.org"

gem "activerecord", "~> 3.2.0"
gem "sqlite3", "~> 1.3.0"
gem "activerecord", "~> 7.2.0"

gemspec path: "../"
31 changes: 30 additions & 1 deletion lib/arel-helpers/join_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class << self
# This method encapsulates that functionality and yields an intermediate object for chaining.
# It also allows you to use an outer join instead of the default inner via the join_type arg.
def join_association(table, association, join_type = Arel::Nodes::InnerJoin, options = {}, &block)
if version >= '6.1.0'
if version >= "7.2.0"
join_association_7_2_0(table, association, join_type, options, &block)
elsif version >= '6.1.0'
join_association_6_1_0(table, association, join_type, options, &block)
elsif version >= '6.0.0'
join_association_6_0_0(table, association, join_type, options, &block)
Expand Down Expand Up @@ -262,6 +264,33 @@ def join_association_6_1_0(table, association, join_type, options = {})
end
end

def join_association_7_2_0(table, association, join_type, options = {})
aliases = options.fetch(:aliases, []).index_by(&:table_name)
associations = association.is_a?(Array) ? association : [association]

alias_tracker = ActiveRecord::Associations::AliasTracker.create(
table.connection_pool, table.name, {}
)

join_dependency = ActiveRecord::Associations::JoinDependency.new(
table, table.arel_table, associations, join_type
)

constraints = join_dependency.join_constraints([], alias_tracker, [])

constraints.map do |join|
apply_aliases(join, aliases)

right = if block_given?
yield join.left.name.to_sym, join.right
else
join.right
end

join_type.new(join.left, right)
end
end

def apply_aliases(node, aliases)
case node
when Arel::Nodes::Join
Expand Down

0 comments on commit 024f6c7

Please sign in to comment.