From f29290ad11463aefe3d1ffec5c508348d7a5bd52 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 2 Nov 2017 16:08:42 -0400 Subject: [PATCH] FIX: don't count whispers in user stats post_count --- lib/post_creator.rb | 2 +- spec/components/post_creator_spec.rb | 37 +++++++++++++++++----------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index be0e6a8026..1e1ae5f806 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -473,7 +473,7 @@ class PostCreator end unless @post.topic.private_message? - @user.user_stat.post_count += 1 + @user.user_stat.post_count += 1 if @post.post_type == Post.types[:regular] @user.user_stat.topic_count += 1 if @post.is_first_post? end diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index f3d2e8350a..4c753a0dc1 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -387,27 +387,34 @@ describe PostCreator do it 'whispers do not mess up the public view' do first = PostCreator.new(user, - topic_id: topic.id, - raw: 'this is the first post').create + topic_id: topic.id, + raw: 'this is the first post').create + + user_stat = user.user_stat whisper = PostCreator.new(user, - topic_id: topic.id, - reply_to_post_number: 1, - post_type: Post.types[:whisper], - raw: 'this is a whispered reply').create + topic_id: topic.id, + reply_to_post_number: 1, + post_type: Post.types[:whisper], + raw: 'this is a whispered reply').create + + # don't count whispers in user stats + expect(user_stat.reload.post_count).to eq(1) expect(whisper).to be_present expect(whisper.post_type).to eq(Post.types[:whisper]) whisper_reply = PostCreator.new(user, - topic_id: topic.id, - reply_to_post_number: whisper.post_number, - post_type: Post.types[:regular], - raw: 'replying to a whisper this time').create + topic_id: topic.id, + reply_to_post_number: whisper.post_number, + post_type: Post.types[:regular], + raw: 'replying to a whisper this time').create expect(whisper_reply).to be_present expect(whisper_reply.post_type).to eq(Post.types[:whisper]) + expect(user_stat.reload.post_count).to eq(1) + # date is not precise enough in db whisper_reply.reload @@ -423,10 +430,12 @@ describe PostCreator do expect(topic.posts_count).to eq(1) expect(topic.highest_staff_post_number).to eq(3) - topic.update_columns(highest_staff_post_number: 0, - highest_post_number: 0, - posts_count: 0, - last_posted_at: 1.year.ago) + topic.update_columns( + highest_staff_post_number: 0, + highest_post_number: 0, + posts_count: 0, + last_posted_at: 1.year.ago + ) Topic.reset_highest(topic.id)