diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index 9d35572f0..b1538585a 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -64,6 +64,12 @@ class PostDestroyer def staff_recovered @post.recover! + + if author = @post.user + author.user_stat.post_count += 1 + author.user_stat.save! + end + @post.publish_change_to_clients! :recovered TopicTrackingState.publish_recover(@post.topic) if @post.topic && @post.post_number == 1 end diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index 00573a5f4..aacad3ca9 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -162,6 +162,34 @@ describe PostDestroyer do post_action = author.user_actions.where(action_type: UserAction::REPLY, target_post_id: reply.id).first expect(post_action).to be_present end + + describe "post_count recovery" do + before do + post + @user = post.user + expect(@user.user_stat.post_count).to eq(1) + end + + context "recovered by user" do + it "should increment the user's post count" do + PostDestroyer.new(@user, post).destroy + expect(@user.user_stat.post_count).to eq(1) + + PostDestroyer.new(@user, post.reload).recover + expect(@user.reload.user_stat.post_count).to eq(1) + end + end + + context "recovered by admin" do + it "should increment the user's post count" do + PostDestroyer.new(moderator, post).destroy + expect(@user.user_stat.post_count).to eq(0) + + PostDestroyer.new(admin, post).recover + expect(@user.reload.user_stat.post_count).to eq(1) + end + end + end end describe 'basic destroying' do