FIX: Listing topics with muted mixed-case tags (#10268)

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.

diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index bf614e7..f030c83 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 d6e56a0..6d97abf 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

GitHub sha: 5f3dfce4

This commit appears in #10268 which was merged by davidtaylorhq.