diff --git a/app/logical/concerns/searchable.rb b/app/logical/concerns/searchable.rb index 7f5a3c5c6..02df65732 100644 --- a/app/logical/concerns/searchable.rb +++ b/app/logical/concerns/searchable.rb @@ -505,7 +505,7 @@ module Searchable def find_ordered(ids) order_clause = [] ids.each do |id| - order_clause << sanitize_sql_array(["ID=? DESC", id]) + order_clause << sanitize_sql_array(["#{qualified_column_for(:id)} = ? DESC", id]) end where(id: ids).order(Arel.sql(order_clause.join(', '))) end diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index aa2f7face..295dbd8d0 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -492,6 +492,13 @@ class PostsControllerTest < ActionDispatch::IntegrationTest assert_redirected_to(post_path(@post, tags: "aaaa")) end + should "render for a ordfav: search" do + @post = as(@user) { create(:post, tag_string: "fav:me") } + get random_posts_path, params: { tags: "ordfav:#{@user.name}" } + + assert_redirected_to(post_path(@post, tags: "ordfav:#{@user.name}")) + end + should "return a 404 when no random posts can be found" do get random_posts_path, params: { tags: "qoigjegoi" } assert_response 404