From 4024eb078c8f649945a0355a5711c45e7129edf4 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 22 Jul 2021 15:00:27 +0530 Subject: [PATCH] FIX: filter by "nobody" was broken (#176) Meta ref: https://meta.discourse.org/t/filter-by-nobody-seems-broken/197770/ --- plugin.rb | 3 ++- spec/components/topic_query_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 60dcbf3..bb6fa4e 100644 --- a/plugin.rb +++ b/plugin.rb @@ -211,7 +211,8 @@ after_initialize do if user_id || special 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 if username == "*" filter = "a.assigned_to_id IS NOT NULL" diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index 09519e0..b8242ee 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -141,6 +141,19 @@ describe TopicQuery do 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) topic.tap do |t| t.posts << Fabricate(:post)