FIX: summary should not include certain post types

This commit is contained in:
Neil Lalonde 2016-12-01 12:01:23 -05:00
parent 69ff0e48b4
commit 985daf5c72
2 changed files with 25 additions and 2 deletions

View File

@ -137,6 +137,8 @@ class UserNotifications < ActionMailer::Base
@popular_posts = if SiteSetting.digest_posts > 0 @popular_posts = if SiteSetting.digest_posts > 0
Post.for_mailing_list(user, min_date) Post.for_mailing_list(user, min_date)
.where('posts.post_type = ?', Post.types[:regular])
.where('posts.deleted_at IS NULL AND posts.hidden = false AND posts.user_deleted = false')
.where("posts.post_number > ? AND posts.score > ?", 1, 5.0) .where("posts.post_number > ? AND posts.score > ?", 1, 5.0)
.order("posts.score DESC") .order("posts.score DESC")
.limit(SiteSetting.digest_posts) .limit(SiteSetting.digest_posts)

View File

@ -155,8 +155,7 @@ describe UserNotifications do
context "with new topics" do context "with new topics" do
before do before do
Topic.stubs(:for_digest).returns([Fabricate(:topic, user: Fabricate(:coding_horror))]) Fabricate(:topic, user: Fabricate(:coding_horror))
Topic.stubs(:new_since_last_seen).returns(Topic.none)
end end
it "works" do it "works" do
@ -184,6 +183,28 @@ describe UserNotifications do
expect(html).to_not include deleted.title expect(html).to_not include deleted.title
expect(html).to_not include post.raw expect(html).to_not include post.raw
end end
it "excludes whispers and other post types that don't belong" do
t = Fabricate(:topic, user: Fabricate(:user), title: "Who likes the same stuff I like?")
whisper = Fabricate(:post, topic: t, score: 100.0, post_number: 2, raw: "You like weird stuff", post_type: Post.types[:whisper])
mod_action = Fabricate(:post, topic: t, score: 100.0, post_number: 3, raw: "This topic unlisted", post_type: Post.types[:moderator_action])
small_action = Fabricate(:post, topic: t, score: 100.0, post_number: 4, raw: "A small action", post_type: Post.types[:small_action])
html = subject.html_part.body.to_s
expect(html).to_not include whisper.raw
expect(html).to_not include mod_action.raw
expect(html).to_not include small_action.raw
end
it "excludes deleted and hidden posts" do
t = Fabricate(:topic, user: Fabricate(:user), title: "Post objectionable stuff here")
deleted = Fabricate(:post, topic: t, score: 100.0, post_number: 2, raw: "This post is uncalled for", deleted_at: 5.minutes.ago)
hidden = Fabricate(:post, topic: t, score: 100.0, post_number: 3, raw: "Try to find this post", hidden: true, hidden_at: 5.minutes.ago, hidden_reason_id: Post.hidden_reasons[:flagged_by_tl3_user])
user_deleted = Fabricate(:post, topic: t, score: 100.0, post_number: 4, raw: "I regret this post", user_deleted: true)
html = subject.html_part.body.to_s
expect(html).to_not include deleted.raw
expect(html).to_not include hidden.raw
expect(html).to_not include user_deleted.raw
end
end end
end end