diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index 01f14a1f80a..f3379aafdbc 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -290,9 +290,11 @@ class PostRevisor private_message = @post.topic.private_message? prev_owner_user_stat = prev_owner.user_stat - prev_owner_user_stat.post_count -= 1 - prev_owner_user_stat.topic_count -= 1 if @post.is_first_post? - prev_owner_user_stat.likes_received -= likes if !private_message + unless private_message + prev_owner_user_stat.post_count -= 1 if @post.post_type == Post.types[:regular] + prev_owner_user_stat.topic_count -= 1 if @post.is_first_post? + prev_owner_user_stat.likes_received -= likes + end prev_owner_user_stat.update_topic_reply_count if @post.created_at == prev_owner.user_stat.first_post_created_at @@ -302,9 +304,11 @@ class PostRevisor prev_owner_user_stat.save! new_owner_user_stat = new_owner.user_stat - new_owner_user_stat.post_count += 1 - new_owner_user_stat.topic_count += 1 if @post.is_first_post? - new_owner_user_stat.likes_received += likes if !private_message + unless private_message + new_owner_user_stat.post_count += 1 if @post.post_type == Post.types[:regular] + new_owner_user_stat.topic_count += 1 if @post.is_first_post? + new_owner_user_stat.likes_received += likes + end new_owner_user_stat.update_topic_reply_count new_owner_user_stat.save! end diff --git a/spec/services/post_owner_changer_spec.rb b/spec/services/post_owner_changer_spec.rb index ea88731ea0e..f4896ea1972 100644 --- a/spec/services/post_owner_changer_spec.rb +++ b/spec/services/post_owner_changer_spec.rb @@ -131,19 +131,43 @@ describe PostOwnerChanger do expect(user_a_stat.likes_received).to eq(1) end + it "handles whispers" do + whisper = PostCreator.new( + editor, + topic_id: p1.topic_id, + reply_to_post_number: 1, + post_type: Post.types[:whisper], + raw: 'this is a whispered reply' + ).create + + user_stat = editor.user_stat + + expect { + described_class.new( + post_ids: [whisper.id], + topic_id: topic.id, + new_owner: Fabricate(:admin), + acting_user: editor + ).change_owner! + }.to_not change { user_stat.reload.post_count } + end + context 'private message topic' do let(:topic) { Fabricate(:private_message_topic) } it "should update users' counts" do PostAction.act(p2user, p1, PostActionType.types[:like]) - change_owners + expect { + change_owners + }.to_not change { p1user.user_stat.post_count } expect(p1user.user_stat.likes_received).to eq(0) user_a_stat = user_a.user_stat expect(user_a_stat.first_post_created_at).to be_present expect(user_a_stat.likes_received).to eq(0) + expect(user_a_stat.post_count).to eq(0) end end