FIX: Post count wasn't recovered when a post is recovered.

This commit is contained in:
Guo Xiang Tan 2016-06-13 11:25:06 +08:00
parent 142b74b01b
commit 0c8dd28395
No known key found for this signature in database
GPG Key ID: 19C321C8952B0F72
2 changed files with 34 additions and 0 deletions

View File

@ -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

View File

@ -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