From b06b0a6607938ef0d609a7f0d74ab685386d0b55 Mon Sep 17 00:00:00 2001 From: Jonas S Date: Mon, 14 Mar 2022 14:22:59 +0100 Subject: [PATCH] ISSUE-121: Drop support for ActiveRecord older than 6.0 --- .github/workflows/build.yml | 10 +----- CHANGELOG.md | 2 ++ Gemfile | 6 +--- ISSUE_TEMPLATE.md | 2 +- baby_squeel.gemspec | 2 +- .../active_record/query_methods.rb | 12 +------ .../active_record/version_helper.rb | 9 ----- lib/baby_squeel/join_dependency.rb | 35 +++---------------- .../join_dependency/injector5_2_spec.rb | 32 ----------------- .../__snapshots__/joining_spec.yaml | 3 -- spec/integration/joining_spec.rb | 10 ++---- spec/integration/rails_integration_spec.rb | 4 --- 12 files changed, 14 insertions(+), 113 deletions(-) delete mode 100644 spec/baby_squeel/join_dependency/injector5_2_spec.rb diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3128643..dd7ea21 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a0a78..e35697f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [Unreleased] +- Drop support for ActiveRecord older than 6.0. + ## [1.4.4] - 2022-02-07 ### Fixed diff --git a/Gemfile b/Gemfile index 63653d8..fc3c017 100644 --- a/Gemfile +++ b/Gemfile @@ -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') diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 6c69875..1597705 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -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 diff --git a/baby_squeel.gemspec b/baby_squeel.gemspec index 0f96fe0..ab42740 100644 --- a/baby_squeel.gemspec +++ b/baby_squeel.gemspec @@ -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' diff --git a/lib/baby_squeel/active_record/query_methods.rb b/lib/baby_squeel/active_record/query_methods.rb index e372a1d..267f69e 100644 --- a/lib/baby_squeel/active_record/query_methods.rb +++ b/lib/baby_squeel/active_record/query_methods.rb @@ -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 @@ -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 diff --git a/lib/baby_squeel/active_record/version_helper.rb b/lib/baby_squeel/active_record/version_helper.rb index c46532a..2be8b64 100644 --- a/lib/baby_squeel/active_record/version_helper.rb +++ b/lib/baby_squeel/active_record/version_helper.rb @@ -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 diff --git a/lib/baby_squeel/join_dependency.rb b/lib/baby_squeel/join_dependency.rb index 2656456..bdde798 100644 --- a/lib/baby_squeel/join_dependency.rb +++ b/lib/baby_squeel/join_dependency.rb @@ -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: @@ -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. @@ -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 diff --git a/spec/baby_squeel/join_dependency/injector5_2_spec.rb b/spec/baby_squeel/join_dependency/injector5_2_spec.rb deleted file mode 100644 index 067b3a0..0000000 --- a/spec/baby_squeel/join_dependency/injector5_2_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper' - -describe BabySqueel::JoinDependency::Injector5_2 do - let(:join_path) { - BabySqueel::Join.new([]) - } - - let(:joins_values) { - [:something, join_path, {a: :b}] - } - - subject(:injector) { described_class.new(joins_values) } - - describe '#group_by' do - it 'never yields JoinPath instances to the block' do - injector.group_by do |join| - expect(join).not_to eq(join_path) - end - end - - it 'groups JoinPath into :association_join' do - buckets = injector.group_by { :other } - expect(buckets[:other]).to eq([:something, { a: :b }]) - expect(buckets[:association_join]).to eq([join_path]) - end - - it 'can accompany other :association_joins' do - buckets = injector.group_by { :association_join } - expect(buckets[:association_join]).to eq(joins_values) - end - end -end diff --git a/spec/integration/__snapshots__/joining_spec.yaml b/spec/integration/__snapshots__/joining_spec.yaml index e9fa42e..628feb9 100644 --- a/spec/integration/__snapshots__/joining_spec.yaml +++ b/spec/integration/__snapshots__/joining_spec.yaml @@ -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" diff --git a/spec/integration/joining_spec.rb b/spec/integration/joining_spec.rb index 4093be8..02f7ecf 100644 --- a/spec/integration/joining_spec.rb +++ b/spec/integration/joining_spec.rb @@ -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 @@ -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 } @@ -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 } diff --git a/spec/integration/rails_integration_spec.rb b/spec/integration/rails_integration_spec.rb index 8aa6ee3..a6dd3dc 100644 --- a/spec/integration/rails_integration_spec.rb +++ b/spec/integration/rails_integration_spec.rb @@ -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