FIX: exclude popular posts from deleted topics

This commit is contained in:
Neil Lalonde 2016-11-22 13:23:21 -05:00
parent db4b3a7aa4
commit 86deec3528
2 changed files with 19 additions and 1 deletions

View File

@ -108,9 +108,17 @@ class UserNotifications < ActionMailer::Base
topics_for_digest = Topic.for_digest(user, min_date, limit: SiteSetting.digest_topics + 3, top_order: true).to_a
@popular_topics = topics_for_digest[0,SiteSetting.digest_topics]
@popular_posts = SiteSetting.digest_posts > 0 ? Post.where("post_number > ? AND score > ? AND created_at > ?", 1, 5.0, min_date).order("score DESC").limit(SiteSetting.digest_posts) : []
@other_new_for_you = topics_for_digest.size > SiteSetting.digest_topics ? topics_for_digest[SiteSetting.digest_topics..-1] : []
@popular_posts = if SiteSetting.digest_posts > 0
Post.public_posts
.where("posts.post_number > ? AND posts.score > ? AND posts.created_at > ?", 1, 5.0, min_date)
.order("posts.score DESC")
.limit(SiteSetting.digest_posts)
else
[]
end
topic_lookup = TopicUser.lookup_for(user, @other_new_for_you)
@other_new_for_you.each { |t| t.user_data = topic_lookup[t.id] }

View File

@ -175,7 +175,17 @@ describe UserNotifications do
expect(subject.subject).to match(/Try Discourse/)
expect(subject.subject).not_to match(/Discourse Meta/)
end
it "excludes deleted topics and their posts" do
deleted = Fabricate(:topic, user: Fabricate(:user), title: "Delete this topic plz")
post = Fabricate(:post, topic: deleted, score: 100.0, post_number: 2, raw: "Your wish is my command")
deleted.trash!
html = subject.html_part.body.to_s
expect(html).to_not include deleted.title
expect(html).to_not include post.raw
end
end
end
describe '.user_replied' do