diff --git a/app/models/topic.rb b/app/models/topic.rb index ef9ec5b8c1f..40f6fea8c5c 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -373,7 +373,7 @@ class Topic < ActiveRecord::Base muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id) unless muted_tag_ids.empty? topics = topics.joins("LEFT OUTER JOIN topic_tags ON topic_tags.topic_id = topics.id") - .where("topic_tags.tag_id NOT IN (?)", muted_tag_ids) + .where("topic_tags.tag_id NOT IN (?) OR topic_tags.tag_id is null", muted_tag_ids) end topics diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 73567611dda..385bb3cfaff 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1413,6 +1413,17 @@ describe Topic do expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic]) end + it "returns topics with no tags too" do + user = Fabricate(:user) + muted_tag, other_tag = Fabricate(:tag), Fabricate(:tag) + TagUser.change(user.id, muted_tag.id, TagUser.notification_levels[:muted]) + topic1 = Fabricate(:topic, tags: [muted_tag]) + topic2 = Fabricate(:topic, tags: [other_tag]) + topic3 = Fabricate(:topic) + + expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to contain_exactly(topic2, topic3) + end + it "sorts by category notification levels" do category1, category2 = Fabricate(:category), Fabricate(:category) 2.times {|i| Fabricate(:topic, category: category1) }