Fix #5267: order[custom] no longer works when only a single ID is being searched
This commit is contained in:
@@ -249,8 +249,9 @@ module Searchable
|
||||
# Post.order_custom("1,2,3") => [post #1, post #2, post #3]
|
||||
def order_custom(string)
|
||||
operator, ids = RangeParser.parse(string, :integer)
|
||||
return none unless operator == :in
|
||||
return none unless operator in :in | :eq
|
||||
|
||||
ids = Array.wrap(ids)
|
||||
in_order_of(:id, ids)
|
||||
rescue RangeParser::ParseError
|
||||
none
|
||||
|
||||
@@ -334,6 +334,14 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(0, response.parsed_body.size)
|
||||
end
|
||||
|
||||
should "work if the search[order]=custom param is used with a single id" do
|
||||
tags = create_list(:tag, 2, post_count: 42)
|
||||
get tags_path, params: { search: { id: tags[0].id, order: "custom" } }, as: :json
|
||||
|
||||
assert_response :success
|
||||
assert_equal([tags[0].id], response.parsed_body.pluck("id"))
|
||||
end
|
||||
|
||||
should "support the expiry parameter" do
|
||||
get posts_path, as: :json, params: { expiry: "1" }
|
||||
|
||||
|
||||
@@ -1359,7 +1359,7 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
|
||||
as(create(:gold_user)) do
|
||||
assert_tag_match([p2, p1, p3], "id:#{p2.id},#{p1.id},#{p3.id} order:custom")
|
||||
assert_tag_match([], "id:#{p1.id} order:custom")
|
||||
assert_tag_match([p1], "id:#{p1.id} order:custom")
|
||||
assert_tag_match([], "id:>0 order:custom")
|
||||
assert_tag_match([], "id:1,2 id:2,3 order:custom")
|
||||
assert_tag_match([], "order:custom")
|
||||
|
||||
Reference in New Issue
Block a user