diff --git a/app/logical/concerns/searchable.rb b/app/logical/concerns/searchable.rb index b4b7bdc32..b0a7a4a2e 100644 --- a/app/logical/concerns/searchable.rb +++ b/app/logical/concerns/searchable.rb @@ -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 diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index 6183f067f..f0ab1423a 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -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" } diff --git a/test/unit/post_query_builder_test.rb b/test/unit/post_query_builder_test.rb index c65b6ff56..59fc281d4 100644 --- a/test/unit/post_query_builder_test.rb +++ b/test/unit/post_query_builder_test.rb @@ -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")