From abf4ca9774d080d561aa0110eb13b19d77438cd7 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 10 Apr 2019 13:10:21 -0400 Subject: [PATCH] FIX: Should be able to recover a user deleted post if raw didn't change --- lib/post_destroyer.rb | 4 +++- spec/components/post_destroyer_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index 10e44f23fdf..c30d7b56be8 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -188,7 +188,9 @@ class PostDestroyer # has internal transactions, if we nest then there are some very high risk deadlocks last_revision = @post.revisions.last - @post.revise(@user, { raw: last_revision.modifications["raw"][0] }, force_new_version: true) if last_revision.present? + if last_revision.present? && last_revision.modifications['raw'].present? + @post.revise(@user, { raw: last_revision.modifications["raw"][0] }, force_new_version: true) + end end private diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index 115d5d2e777..a5ac65eafc9 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -189,6 +189,16 @@ describe PostDestroyer do end context "recovered by user" do + + it "doesn't raise an error when the raw doesn't change" do + PostRevisor.new(@reply).revise!( + @user, + { edit_reason: 'made a change' }, + force_new_version: true + ) + PostDestroyer.new(@user, @reply.reload).recover + end + it "should increment the user's post count" do PostDestroyer.new(@user, @reply).destroy expect(@user.user_stat.topic_count).to eq(1)