Files
danbooru/test/functional/modqueue_controller_test.rb
evazion 59f166a637 Fix #5057: Modqueue: filtering by tag breaks ordering
Fix the order dropdown box on the modqueue page not working when filtering by tag.

This happened because when you do a tag search, the default order is set to `ORDER BY posts.id DESC`.
When you applied another order with the dropdown box, the new order would be tacked on to the old
ordering as a tiebreaker instead of replacing it, producing e.g. `ORDER BY posts.id DESC, queued_at DESC`
instead of `ORDER BY queued_at DESC`. The default order would always win because `posts.id` is
unique and doesn't have ties.

The fix is to have orders always override the previous order instead of adding to it.

Note that now if you use an `order:`, `ordfav:`, or `ordpool:` metatag in the search box on the
modqueue page, they will always be ignored in favor of the dropdown box.
2022-09-28 00:29:50 -05:00

50 lines
1.5 KiB
Ruby

require 'test_helper'
class ModqueueControllerTest < ActionDispatch::IntegrationTest
context "The modqueue controller" do
setup do
@admin = create(:admin_user)
@user = create(:user)
@post = create(:post, is_pending: true)
end
context "index action" do
should "render" do
get_auth modqueue_index_path, @admin
assert_response :success
end
should "render for a json response" do
get_auth modqueue_index_path, @admin, as: :json
assert_response :success
end
should "support the only= URL param" do
get_auth modqueue_index_path(only: "rating"), @admin, as: :json
assert_response :success
assert_equal([{ "rating" => @post.rating }], response.parsed_body)
end
should "order posts correctly when searching for tags" do
post1 = create(:post, tag_string: "touhou", is_pending: true, score: 5)
post2 = create(:post, tag_string: "touhou", is_pending: true, score: 10)
post3 = create(:post, tag_string: "touhou", is_pending: true, score: 15)
get_auth modqueue_index_path(search: { tags: "touhou", order: "score_asc" }), @admin, as: :json
assert_response :success
assert_equal([post1.id, post2.id, post3.id], response.parsed_body.pluck("id"))
end
should "include appealed posts in the modqueue" do
@appeal = create(:post_appeal)
get_auth modqueue_index_path, @admin
assert_response :success
assert_select "#post-#{@appeal.post_id}"
end
end
end
end