From 6f7b6a333352d01be6e35bfab11414faf82e145b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 11 Apr 2019 16:21:00 -0400 Subject: [PATCH] FIX: Disagree and Restore should not revert edits --- app/models/reviewable_flagged_post.rb | 4 +--- lib/post_destroyer.rb | 2 ++ spec/components/post_destroyer_spec.rb | 12 +++++++++++- spec/models/reviewable_flagged_post_spec.rb | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb index 4b1acb01468..67ae263386a 100644 --- a/app/models/reviewable_flagged_post.rb +++ b/app/models/reviewable_flagged_post.rb @@ -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) diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index c30d7b56be8..cd53ab61f4e 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -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 diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index a5ac65eafc9..6a8808447c6 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -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) diff --git a/spec/models/reviewable_flagged_post_spec.rb b/spec/models/reviewable_flagged_post_spec.rb index ab63024ebc4..956173eea1e 100644 --- a/spec/models/reviewable_flagged_post_spec.rb +++ b/spec/models/reviewable_flagged_post_spec.rb @@ -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