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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user