Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with ActiveRecord 7.2 #535

Merged
merged 3 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ 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"
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"
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
Expand Down
29 changes: 25 additions & 4 deletions lib/pg_search/scope_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,32 @@ 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 }

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)
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"
Expand Down
Loading