FIX: Disagree and Restore should not revert edits

This commit is contained in:
Robin Ward 2019-04-11 16:21:00 -04:00
parent 60db57acc0
commit 6f7b6a3333
4 changed files with 15 additions and 4 deletions

View File

@ -154,9 +154,7 @@ class ReviewableFlaggedPost < Reviewable
end
def perform_disagree_and_restore(performed_by, args)
result = perform_disagree(performed_by, args)
PostDestroyer.new(performed_by, post).recover
result
perform_disagree(performed_by, args)
end
def perform_disagree(performed_by, args)

View File

@ -181,6 +181,8 @@ class PostDestroyer
end
def user_recovered
return unless @post.user_deleted?
Post.transaction do
@post.update_column(:user_deleted, false)
@post.skip_unique_check = true

View File

@ -188,7 +188,7 @@ describe PostDestroyer do
expect(recovered_topic.deleted_by_id).to be_nil
end
context "recovered by user" do
context "recover" do
it "doesn't raise an error when the raw doesn't change" do
PostRevisor.new(@reply).revise!(
@ -199,6 +199,16 @@ describe PostDestroyer do
PostDestroyer.new(@user, @reply.reload).recover
end
it "won't recover a non user-deleted post" do
PostRevisor.new(@reply).revise!(
admin,
{ raw: 'this is a change to the post' },
force_new_version: true
)
PostDestroyer.new(@user, @reply.reload).recover
expect(@reply.reload.raw).to eq('this is a change to the post')
end
it "should increment the user's post count" do
PostDestroyer.new(@user, @reply).destroy
expect(@user.user_stat.topic_count).to eq(1)

View File

@ -173,6 +173,7 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
expect(reviewable).to be_rejected
expect(score.reload).to be_disagreed
expect(post.user_deleted?).to eq(false)
expect(post.hidden?).to eq(false)
end
end