From 21dd2ccd43aa338f284f67d2cd0bd8f11d8e2ce2 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 2 Nov 2017 17:11:08 -0400 Subject: [PATCH] FIX: only count regular posts in user stats when deleting --- lib/post_destroyer.rb | 4 ++-- spec/components/post_destroyer_spec.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index 5c8830e96da..a449d55255b 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -231,8 +231,8 @@ class PostDestroyer author.user_stat.first_post_created_at = author.posts.order('created_at ASC').first.try(:created_at) end - unless @topic.nil? && !@post.is_first_post? - author.user_stat.post_count -= 1 # TODO: deleting a regular post + if @post.post_type == Post.types[:regular] && !(@topic.nil? && !@post.is_first_post?) + author.user_stat.post_count -= 1 end author.user_stat.topic_count -= 1 if @post.is_first_post? diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index 4888ebb3b40..9e168924c29 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -308,6 +308,21 @@ describe PostDestroyer do author.reload }.to change { author.post_count }.by(-1) end + + it "doesn't count whispers" do + user_stat = admin.user_stat + whisper = PostCreator.new( + admin, + topic_id: post.topic.id, + reply_to_post_number: 1, + post_type: Post.types[:whisper], + raw: 'this is a whispered reply' + ).create + expect(user_stat.reload.post_count).to eq(0) + expect { + PostDestroyer.new(admin, whisper).destroy + }.to_not change { user_stat.reload.post_count } + end end end