FIX: filter by "nobody" was broken (#176)

Meta ref: https://meta.discourse.org/t/filter-by-nobody-seems-broken/197770/
This commit is contained in:
Arpit Jalan 2021-07-22 15:00:27 +05:30 committed by GitHub
parent c572e21493
commit 4024eb078c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -211,7 +211,8 @@ after_initialize do
if user_id || special if user_id || special
if username == "nobody" if username == "nobody"
results = results.joins("LEFT JOIN assignments a ON a.topic_id = topics.id AND a.assigned_to_id IS NULL") results = results.joins("LEFT JOIN assignments a ON a.topic_id = topics.id")
.where("a.assigned_to_id IS NULL")
else else
if username == "*" if username == "*"
filter = "a.assigned_to_id IS NOT NULL" filter = "a.assigned_to_id IS NOT NULL"

View File

@ -141,6 +141,19 @@ describe TopicQuery do
end end
end end
context 'assigned' do
it "filters assigned topics correctly" do
assigned_topic = Fabricate(:post).topic
unassigned_topic = Fabricate(:topic)
TopicAssigner.new(assigned_topic, user).assign(user)
query = TopicQuery.new(user, assigned: 'nobody').list_latest
expect(query.topics.length).to eq(1)
expect(query.topics.first).to eq(unassigned_topic)
end
end
def assign_to(topic, user) def assign_to(topic, user)
topic.tap do |t| topic.tap do |t|
t.posts << Fabricate(:post) t.posts << Fabricate(:post)