From 2142445c4b3ea342cee5477ed101c0bda42cd9a6 Mon Sep 17 00:00:00 2001 From: Zeke Gabrielse Date: Fri, 17 May 2024 15:15:51 -0500 Subject: [PATCH] add support for rails 7.2 --- .github/workflows/run_tests.yml | 3 +++ .github/workflows/run_tests_on_head.yml | 2 +- CHANGELOG.md | 2 ++ gemfiles/rails_7_2.gemfile | 11 +++++++++++ lib/active_record_where_assoc/active_record_compat.rb | 2 +- test/support/base_test_model.rb | 4 ++-- 6 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 gemfiles/rails_7_2.gemfile diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 4267cb3..df9b2d2 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -28,6 +28,9 @@ jobs: fail-fast: false matrix: include: + - gemfile: gemfiles/rails_7_2.gemfile + ruby_version: '3.3' + - gemfile: gemfiles/rails_7_1.gemfile ruby_version: '3.2' - gemfile: gemfiles/rails_7_1.gemfile diff --git a/.github/workflows/run_tests_on_head.yml b/.github/workflows/run_tests_on_head.yml index 3989329..ace1879 100644 --- a/.github/workflows/run_tests_on_head.yml +++ b/.github/workflows/run_tests_on_head.yml @@ -30,7 +30,7 @@ jobs: ruby_version: head - gemfile: gemfiles/rails_head.gemfile ruby_version: 3.2 - - gemfile: gemfiles/rails_7_1.gemfile + - gemfile: gemfiles/rails_7_2.gemfile ruby_version: head runs-on: ubuntu-latest services: diff --git a/CHANGELOG.md b/CHANGELOG.md index caef650..d0c27ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +* Add compatibility for Rails 7.2 + # 1.1.4 - 2023-10-10 * Add compatibility for Rails 7.1 diff --git a/gemfiles/rails_7_2.gemfile b/gemfiles/rails_7_2.gemfile new file mode 100644 index 0000000..70e7afa --- /dev/null +++ b/gemfiles/rails_7_2.gemfile @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "activerecord", github: "rails/rails", branch: "7-2-stable" +gem "sqlite3", "~> 1.4.0" +gem "pg", "~> 1.1" +gem "mysql2", "~> 0.5" if ENV["CI"] || ENV["ALL_DB"] || ENV["DB"] == "mysql" +gem "prime" + +gemspec path: "../" diff --git a/lib/active_record_where_assoc/active_record_compat.rb b/lib/active_record_where_assoc/active_record_compat.rb index 5806417..1fd6781 100644 --- a/lib/active_record_where_assoc/active_record_compat.rb +++ b/lib/active_record_where_assoc/active_record_compat.rb @@ -72,7 +72,7 @@ def self.parent_reflection(reflection) end end - if ActiveRecord.gem_version >= Gem::Version.new("4.2") + if ActiveRecord.gem_version >= Gem::Version.new("4.2") && ActiveRecord.gem_version < Gem::Version.new("7.2.0.alpha") def self.normalize_association_name(association_name) association_name.to_s end diff --git a/test/support/base_test_model.rb b/test/support/base_test_model.rb index e981e6e..70464be 100644 --- a/test/support/base_test_model.rb +++ b/test/support/base_test_model.rb @@ -94,7 +94,7 @@ def self.create_default!(*source_associations) def create_has_one!(association_name, attrs = {}) association_name = ActiveRecordWhereAssoc::ActiveRecordCompat.normalize_association_name(association_name) - reflection = self.class.reflections[association_name] + reflection = self.class._reflections[association_name] raise "Didn't find association: #{association_name}" unless reflection target_model = reflection.klass @@ -118,7 +118,7 @@ def create_assoc!(association_name, *source_associations) association_name = ActiveRecordWhereAssoc::ActiveRecordCompat.normalize_association_name(association_name) association_macro = association_name.to_s[/^[a-z]+/] - reflection = self.class.reflections[association_name] + reflection = self.class._reflections[association_name] raise "Didn't find association: #{association_name}" unless reflection target_model = options[:target_model] || reflection.klass