SPEC: Do not raise error if topic not exist

SPEC: Do not raise error if topic not exist

From 004cf718b9cb38594ef62cb7b7bab14a979dc48c Mon Sep 17 00:00:00 2001
From: Vinoth Kannan <vinothkannan@vinkas.com>
Date: Fri, 5 Oct 2018 09:37:28 +0530
Subject: [PATCH] SPEC: Do not raise error if topic not exist


diff --git a/spec/integration/assign_spec.rb b/spec/integration/assign_spec.rb
index dc5c900..bc1c3ec 100644
--- a/spec/integration/assign_spec.rb
+++ b/spec/integration/assign_spec.rb
@@ -57,4 +57,28 @@ describe 'integration tests' do
       end
     end
   end
+
+  describe "on before_staff_flag_action event" do
+    let(:post) { Fabricate(:post) }
+    let(:user) { Fabricate(:user) }
+    let(:args) {{ post: post, user: user }}
+
+    before do
+      SiteSetting.assign_locks_flags = true
+      TopicCustomField.create(
+        topic_id: post.topic_id,
+        name: TopicAssigner::ASSIGNED_TO_ID,
+        value: Discourse.system_user.id
+      )
+    end
+
+    it "do not raise error if topic is deleted" do
+      expect { DiscourseEvent.trigger(:before_staff_flag_action, args) }.to raise_error(Discourse::InvalidAccess)
+
+      post.topic.destroy!
+      post.reload
+
+      expect { DiscourseEvent.trigger(:before_staff_flag_action, args) }.not_to raise_error
+    end
+  end
 end

GitHub

1 Like