FIX: mailing list mode digest emails included whispers

This commit is contained in:
Neil Lalonde 2017-01-13 13:46:33 -05:00
parent adb73180f7
commit e8307ac24c
2 changed files with 22 additions and 4 deletions

View File

@ -69,10 +69,13 @@ class Post < ActiveRecord::Base
scope :visible, -> { joins(:topic).where('topics.visible = true').where(hidden: false) }
scope :secured, lambda { |guardian| where('posts.post_type in (?)', Topic.visible_post_types(guardian && guardian.user))}
scope :for_mailing_list, ->(user, since) {
created_since(since)
.joins(:topic)
.where(topic: Topic.for_digest(user, 100.years.ago)) # we want all topics with new content, regardless when they were created
.order('posts.created_at ASC')
q = created_since(since)
.joins(:topic)
.where(topic: Topic.for_digest(user, 100.years.ago)) # we want all topics with new content, regardless when they were created
q = q.where.not(post_type: Post.types[:whisper]) unless user.staff?
q.order('posts.created_at ASC')
}
scope :mailing_list_new_topics, ->(user, since) { for_mailing_list(user, since).where('topics.created_at > ?', since) }
scope :mailing_list_updates, ->(user, since) { for_mailing_list(user, since).where('topics.created_at <= ?', since) }

View File

@ -137,6 +137,21 @@ describe UserNotifications do
expect(subject.subject).to match(/Try Discourse/)
expect(subject.subject).not_to match(/Discourse Meta/)
end
it "excludes whispers" do
new_post_in_old_topic
whisper = Fabricate(:post, topic: old_topic, created_at: 1.hour.ago, raw: "This is secret", post_type: Post.types[:whisper])
expect(subject.html_part.body.to_s).to include old_topic.title
expect(subject.html_part.body.to_s).to_not include whisper.cooked
end
it "includes whispers for staff" do
user.admin = true; user.save!
new_post_in_old_topic
whisper = Fabricate(:post, topic: old_topic, created_at: 1.hour.ago, raw: "This is secret", post_type: Post.types[:whisper])
expect(subject.html_part.body.to_s).to include old_topic.title
expect(subject.html_part.body.to_s).to include whisper.cooked
end
end
end