From 5f3dfce4eb5081c632ee245c5b531bf927e7a627 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 20 Jul 2020 11:01:29 +0100 Subject: [PATCH] FIX: Listing topics with muted mixed-case tags (#10268) When visiting a tag page directly, we should display all topics, even if that tag is muted. This was not working for mixed-case tags. --- lib/topic_query.rb | 2 +- spec/components/topic_query_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/topic_query.rb b/lib/topic_query.rb index bf614e700ec..f030c83abae 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -890,7 +890,7 @@ class TopicQuery # if viewing the topic list for a muted tag, show all the topics if !opts[:no_tags] && opts[:tags].present? - return list if TagUser.lookup(user, :muted).joins(:tag).where('tags.name = ?', opts[:tags].first).exists? + return list if TagUser.lookup(user, :muted).joins(:tag).where('lower(tags.name) = ?', opts[:tags].first.downcase).exists? end if SiteSetting.remove_muted_tags_from_latest == 'always' diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index d6e56a069de..6d97abfcb9c 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -362,6 +362,22 @@ describe TopicQuery do topic_ids = topic_query.list_new.topics.map(&:id) expect(topic_ids).to contain_exactly(muted_topic.id, tagged_topic.id, muted_tagged_topic.id, untagged_topic.id) end + + it 'is not removed from the tag page itself' do + muted_tag = Fabricate(:tag) + TagUser.create!(user_id: user.id, + tag_id: muted_tag.id, + notification_level: CategoryUser.notification_levels[:muted]) + + muted_topic = Fabricate(:topic, tags: [muted_tag]) + + topic_ids = topic_query.latest_results(tags: [muted_tag.name]).map(&:id) + expect(topic_ids).to contain_exactly(muted_topic.id) + + muted_tag.update(name: "mixedCaseName") + topic_ids = topic_query.latest_results(tags: [muted_tag.name.downcase]).map(&:id) + expect(topic_ids).to contain_exactly(muted_topic.id) + end end context 'a bunch of topics' do