From 9391e7e7bbdf3fe7d6e0f0dabc2af740cb432e89 Mon Sep 17 00:00:00 2001 From: fatkodima Date: Tue, 2 Jul 2024 02:00:33 +0300 Subject: [PATCH 1/3] Fix compatibility with ActiveRecord 7.2 --- .github/workflows/ci.yml | 4 ++++ lib/pg_search/scope_options.rb | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f5b56f7..18ebbee7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,11 +41,15 @@ jobs: - ACTIVE_RECORD_VERSION="~> 6.1.0" - ACTIVE_RECORD_VERSION="~> 7.0.0" - ACTIVE_RECORD_VERSION="~> 7.1.0" + - ACTIVE_RECORD_VERSION="~> 7.2.0.beta2" allow-failure: [false] include: - ruby-version: '3.3' active-record-version-env: ACTIVE_RECORD_BRANCH="main" allow-failure: true + - ruby-version: '3.3' + active-record-version-env: ACTIVE_RECORD_BRANCH="7-2-stable" + allow-failure: true - ruby-version: '3.3' active-record-version-env: ACTIVE_RECORD_BRANCH="7-1-stable" allow-failure: true diff --git a/lib/pg_search/scope_options.rb b/lib/pg_search/scope_options.rb index b03d13d0..d6893b68 100644 --- a/lib/pg_search/scope_options.rb +++ b/lib/pg_search/scope_options.rb @@ -90,10 +90,17 @@ def subquery end def conditions - config.features - .reject { |_feature_name, feature_options| feature_options && feature_options[:sort_only] } - .map { |feature_name, _feature_options| feature_for(feature_name).conditions } - .inject { |accumulator, expression| Arel::Nodes::Or.new(accumulator, expression) } + expressions = + config.features + .reject { |_feature_name, feature_options| feature_options && feature_options[:sort_only] } + .map { |feature_name, _feature_options| feature_for(feature_name).conditions } + + # https://github.com/rails/rails/pull/51492 + if ActiveRecord.version >= Gem::Version.new("7.2.0.beta1") + Arel::Nodes::Or.new(expressions) + else + expressions.inject { |accumulator, expression| Arel::Nodes::Or.new(accumulator, expression) } + end end def order_within_rank From cf258058af8badc6a1bbb8195ab92ef56fb97195 Mon Sep 17 00:00:00 2001 From: Grant Hutchins Date: Sun, 11 Aug 2024 15:32:36 -0500 Subject: [PATCH 2/3] Prefer feature detection over version comparison --- lib/pg_search/scope_options.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/pg_search/scope_options.rb b/lib/pg_search/scope_options.rb index d6893b68..6fe515dd 100644 --- a/lib/pg_search/scope_options.rb +++ b/lib/pg_search/scope_options.rb @@ -95,13 +95,27 @@ def conditions .reject { |_feature_name, feature_options| feature_options && feature_options[:sort_only] } .map { |feature_name, _feature_options| feature_for(feature_name).conditions } - # https://github.com/rails/rails/pull/51492 - if ActiveRecord.version >= Gem::Version.new("7.2.0.beta1") + or_node(expressions) + end + + # https://github.com/rails/rails/pull/51492 + # :nocov: + # standard:disable Lint/DuplicateMethods + or_arity = Arel::Nodes::Or.instance_method(:initialize).arity + case or_arity + when 1 + def or_node(expressions) Arel::Nodes::Or.new(expressions) - else + end + when 2 + def or_node(expressions) expressions.inject { |accumulator, expression| Arel::Nodes::Or.new(accumulator, expression) } end + else + raise "Unsupported arity #{or_arity} for Arel::Nodes::Or#initialize" end + # :nocov: + # standard:enable Lint/DuplicateMethods def order_within_rank config.order_within_rank || "#{primary_key} ASC" From b3d334db2d1d92e1fa6ecf47a89f46530de818ea Mon Sep 17 00:00:00 2001 From: Grant Hutchins Date: Sun, 11 Aug 2024 15:52:12 -0500 Subject: [PATCH 3/3] Update CI for Active Record 7.2 --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18ebbee7..d1405f0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,8 +41,11 @@ jobs: - ACTIVE_RECORD_VERSION="~> 6.1.0" - ACTIVE_RECORD_VERSION="~> 7.0.0" - ACTIVE_RECORD_VERSION="~> 7.1.0" - - ACTIVE_RECORD_VERSION="~> 7.2.0.beta2" + - ACTIVE_RECORD_VERSION="~> 7.2.0" allow-failure: [false] + exclude: + - ruby-version: '3.0' + active-record-version-env: ACTIVE_RECORD_VERSION="~> 7.2.0" include: - ruby-version: '3.3' active-record-version-env: ACTIVE_RECORD_BRANCH="main"