Fix #5132: Modqueue displays active posts when excluding any search term

Fix a bug where searching for a negated tag inside the modqueue would show
active posts.

The bug was that in a search like this:

    Post.in_modqueue.user_tag_match("-solo")

The `in_modqueue` condition would get sucked inside the tag search and negated
when we tried to apply the negation operator to the "solo" tag. So effectively
the `in_modqueue` condition would get negated and we would end up searching for
everything not in the modqueue.
This commit is contained in:
evazion
2022-09-28 00:13:39 -05:00
parent 59f166a637
commit 4c03ea5be3
4 changed files with 40 additions and 5 deletions

View File

@@ -1995,4 +1995,18 @@ class PostTest < ActiveSupport::TestCase
assert_equal("https://www.example.com/data/original/77/d8/77d89bda37ea3af09158ed3282f8334f.gif", @post.file_url)
end
end
context "Searching:" do
context "the user_tag_match method" do
should "should not negate conditions before the search" do
@post1 = create(:post, tag_string: "solo", is_pending: true)
@post2 = create(:post, tag_string: "touhou", is_deleted: true)
assert_equal([@post1.id], Post.pending.anon_tag_match("solo").pluck(:id))
assert_equal([], Post.pending.anon_tag_match("-solo").pluck(:id))
assert_equal([@post2.id], Post.deleted.anon_tag_match("touhou").pluck(:id))
assert_equal([], Post.deleted.anon_tag_match("-touhou").pluck(:id))
end
end
end
end