From 7740b1570b805aeaaf52af4d71ac81dd3f47a832 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Fri, 29 Mar 2019 10:36:29 -0300 Subject: [PATCH] FIX: Avoid the deleted_at scope when recovering a topic from a recently recovered post --- lib/post_destroyer.rb | 2 +- spec/components/post_destroyer_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index 4719d4f5d1d..3c6ea4a5650 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -85,7 +85,7 @@ class PostDestroyer UserActionManager.post_created(@post) DiscourseEvent.trigger(:post_recovered, @post, @opts, @user) if @post.is_first_post? - UserActionManager.topic_created(@post.topic) + UserActionManager.topic_created(topic) DiscourseEvent.trigger(:topic_recovered, topic, @user) StaffActionLogger.new(@user).log_topic_delete_recover(topic, "recover_topic", @opts.slice(:context)) if @user.id != @post.user_id end diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index 3b1706fea22..e6758fa6032 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -177,6 +177,17 @@ describe PostDestroyer do expect(@user.user_stat.post_count).to eq(1) end + it 'Recovers the post correctly' do + PostDestroyer.new(admin, post).destroy + + post.reload + PostDestroyer.new(admin, post).recover + recovered_topic = post.reload.topic + + expect(recovered_topic.deleted_at).to be_nil + expect(recovered_topic.deleted_by_id).to be_nil + end + context "recovered by user" do it "should increment the user's post count" do PostDestroyer.new(@user, @reply).destroy