From defea080848dd622d0d497c252251f6c58bd9e68 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 21 Mar 2022 01:27:53 -0500 Subject: [PATCH] posts: fix exception in random:1 searches. Fix regression in 1ad0e8688. Caused by `relation.order_values` returning an array of Arel nodes instead of an array of strings when doing a `random:1` search. --- app/logical/post_query_builder.rb | 4 +++- test/functional/posts_controller_test.rb | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index 63e74f02d..88d77bc09 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -542,7 +542,9 @@ class PostQueryBuilder # better. def optimize_search(relation, small_search_threshold) return relation unless small_search_threshold.present? - return relation unless relation.order_values.map(&:downcase).in?([["posts.id desc"], ["posts.id asc"]]) + + order_values = relation.order_values.map { |order| order.try(:to_sql) || order.to_s }.map(&:downcase) + return relation unless order_values.in?([["posts.id desc"], ["posts.id asc"]]) if post_count.nil? # If post_count is nil, then the search took too long to count and we don't diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index a9bcf36bc..f4a0c1645 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -323,6 +323,9 @@ class PostsControllerTest < ActionDispatch::IntegrationTest get posts_path, params: { tags: "order:random" } assert_response :success + get posts_path(tags: "random:1") + assert_response :success + get posts_path(random: "1") assert_redirected_to posts_path(tags: "random:20", format: :html)