FIX: summary email excludes all untagged topics if user has muted some tags

This commit is contained in:
Neil Lalonde 2017-07-04 12:51:57 -04:00
parent 35ff5d6796
commit 3964929c75
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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) }