Skip to content

Commit

Permalink
Merge pull request #122 from rocket-turtle/ISSUE-121
Browse files Browse the repository at this point in the history
ISSUE-121: Drop support for ActiveRecord older than 6.0
  • Loading branch information
rzane authored Apr 7, 2022
2 parents b97fe2b + b06b0a6 commit 7b307db
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 113 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,10 @@ jobs:
name: Active Record ${{ matrix.activerecord }} on ruby ${{ matrix.ruby }} (compat=${{ matrix.compat }})
strategy:
matrix:
activerecord: ["5.2.0", "5.2.5", "~> 6.0", "~> 6.1", "~> 7.0"]
activerecord: ["~> 6.0", "~> 6.1", "~> 7.0"]
compat: ["0", "1"]
ruby: [ "2.6", "2.7", "3.0", "3.1"]
exclude:
- activerecord: "5.2.0"
ruby: "3.0"
- activerecord: "5.2.0"
ruby: "3.1"
- activerecord: "5.2.5"
ruby: "3.0"
- activerecord: "5.2.5"
ruby: "3.1"
- activerecord: "~> 7.0"
ruby: "2.6"
env:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [Unreleased]

- Drop support for ActiveRecord older than 6.0.

## [1.4.4] - 2022-02-07

### Fixed
Expand Down
6 changes: 1 addition & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ when 'master'
else
gem 'activerecord', ENV['AR']

if ENV['AR'] == '5.2.0'
gem 'sqlite3', '~> 1.3.6'
else
gem 'sqlite3', '~> 1.4'
end
gem 'sqlite3', '~> 1.4'
end

case ENV.fetch('RANSACK', 'latest')
Expand Down
2 changes: 1 addition & 1 deletion ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require 'minitest/autorun'

gemfile true do
source 'https://rubygems.org'
gem 'activerecord', '~> 5.2.0' # which Active Record version?
gem 'activerecord', '~> 6.0.0' # which Active Record version?
gem 'sqlite3'
gem 'baby_squeel', github: 'rzane/baby_squeel'
end
Expand Down
2 changes: 1 addition & 1 deletion baby_squeel.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|

spec.files = Dir.glob('{lib/**/*,*.{md,txt,gemspec}}')

spec.add_dependency 'activerecord', '>= 5.2', '< 7.1'
spec.add_dependency 'activerecord', '>= 6.0', '< 7.1'
spec.add_dependency 'ransack', '~> 2.3'

spec.add_development_dependency 'bundler', '~> 2'
Expand Down
12 changes: 1 addition & 11 deletions lib/baby_squeel/active_record/query_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def select_association_list(*args)
args[0].extend(BabySqueel::ActiveRecord::QueryMethods::Injector6_1)
super *args
end
elsif BabySqueel::ActiveRecord::VersionHelper.at_least_6_0?
else
private

# Active Record will call `each` on the `joins`. The
Expand All @@ -77,16 +77,6 @@ def build_joins(*args)
args[1] = BabySqueel::JoinDependency::Injector6_0.new(args.second)
super(*args)
end
else
private

# Active Record will call `group_by` on the `joins`. The
# Injector has a custom `group_by` method that handles
# BabySqueel::Join nodes.
def build_joins(*args)
args[1] = BabySqueel::JoinDependency::Injector5_2.new(args.second)
super(*args)
end
end
end
end
Expand Down
9 changes: 0 additions & 9 deletions lib/baby_squeel/active_record/version_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ def self.at_least_6_1?
::ActiveRecord::VERSION::MAJOR > 6 ||
::ActiveRecord::VERSION::MAJOR == 6 && ::ActiveRecord::VERSION::MINOR >= 1
end

def self.at_least_6_0?
::ActiveRecord::VERSION::MAJOR >= 6
end

def self.at_least_5_2_3?
at_least_6_0? ||
::ActiveRecord::VERSION::MAJOR >= 5 && ::ActiveRecord::VERSION::MINOR >= 2 && ::ActiveRecord::VERSION::TINY >= 3
end
end
end
end
35 changes: 4 additions & 31 deletions lib/baby_squeel/join_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@

module BabySqueel
module JoinDependency
# This class allows BabySqueel to slip custom
# joins_values into Active Record's JoinDependency
class Injector5_2 < Array # :nodoc:
# Active Record will call group_by on this object
# in ActiveRecord::QueryMethods#build_joins. This
# allows BabySqueel::Joins to be treated
# like typical join hashes until Polyamorous can
# deal with them.
def group_by
super do |join|
case join
when BabySqueel::Join
:association_join
else
yield join
end
end
end
end

# This class allows BabySqueel to slip custom
# joins_values into Active Record's JoinDependency
class Injector6_0 < Array # :nodoc:
Expand Down Expand Up @@ -75,7 +55,7 @@ def find_alias(associations)
join_root.each_children do |parent, child|
join_dependency.construct_tables_for_association!(parent, child)
end
elsif BabySqueel::ActiveRecord::VersionHelper.at_least_5_2_3?
else
# If we tell join_dependency to construct its tables, Active Record
# handles building the correct aliases and attaching them to its
# JoinDepenencies.
Expand Down Expand Up @@ -147,16 +127,9 @@ def build(relation, buckets)
join_list = join_nodes + joins

alias_tracker = Associations::AliasTracker.create(relation.klass.connection, relation.table.name, join_list)
if BabySqueel::ActiveRecord::VersionHelper.at_least_6_0?
join_dependency = Associations::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::InnerJoin)
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
elsif BabySqueel::ActiveRecord::VersionHelper.at_least_5_2_3?
join_dependency = Associations::JoinDependency.new(relation.klass, relation.table, association_joins)
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
else
# Rails 5.2.0 - 5.2.2
join_dependency = Associations::JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker)
end
join_dependency = Associations::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::InnerJoin)
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)

join_nodes.each do |join|
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
end
Expand Down
32 changes: 0 additions & 32 deletions spec/baby_squeel/join_dependency/injector5_2_spec.rb

This file was deleted.

3 changes: 0 additions & 3 deletions spec/integration/__snapshots__/joining_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@
: SELECT "posts".* FROM "posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id"
LEFT OUTER JOIN "comments" ON "comments"."author_id" = "authors"."id" INNER JOIN
"authors" "authors_posts" ON "authors_posts"."id" = "posts"."author_id"
"#joining when joining explicitly merges bind values 1 (Active Record: v5.2.0)": SELECT
"posts".* FROM "posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id"
AND "authors"."ugly" = 't' INNER JOIN "comments" ON "comments"."author_id" = "authors"."id"
"#joining when joining explicitly merges bind values 1 (Active Record: v6.0)": SELECT
"posts".* FROM "posts" INNER JOIN "authors" ON "authors"."ugly" = 1 AND "authors"."id"
= "posts"."author_id" INNER JOIN "comments" ON "comments"."author_id" = "authors"."id"
Expand Down
10 changes: 3 additions & 7 deletions spec/integration/joining_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
it 'merges bind values' do
relation = Post.joining { ugly_author_comments }

expect(relation).to match_sql_snapshot(variants: ['5.2.0', '6.0', '6.1', '7.0'])
expect(relation).to match_sql_snapshot(variants: ['6.0', '6.1', '7.0'])
end

context 'with complex conditions' do
Expand Down Expand Up @@ -176,9 +176,7 @@
end

it 'outer joins' do
if BabySqueel::ActiveRecord::VersionHelper.at_least_5_2_3?
pending "This feature is known to be broken"
end
pending "This feature is known to be broken"

relation = Post.joining { author.outer.comments }

Expand Down Expand Up @@ -227,9 +225,7 @@
end

it 'joins a through association and then back again' do
if BabySqueel::ActiveRecord::VersionHelper.at_least_5_2_3?
pending "This feature is known to be broken"
end
pending "This feature is known to be broken"

relation = Post.joining { author.posts.author_comments.outer.post.author_comments }

Expand Down
4 changes: 0 additions & 4 deletions spec/integration/rails_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

describe 'test that plain rails still works' do
it 'joins and merge' do
unless BabySqueel::ActiveRecord::VersionHelper.at_least_5_2_3?
pending 'Rails does a LEFT OUTER JOIN for comments in the 5.2.0 version but an INNER JOIN in 5.2.3 +'
end

relation = Author.joins(:posts).merge(Post.joins(:comments).merge(Comment.where(body: 'body')))

expect(relation).to match_sql_snapshot
Expand Down

0 comments on commit 7b307db

Please sign in to comment.