FIX: Unassign on autoclose.

FIX: Unassign on autoclose.

From 0299deaf25bd5707bb69d6d4f3da9f8c97c868df Mon Sep 17 00:00:00 2001
From: Bianca Nenciu <nenciu.bianca@gmail.com>
Date: Wed, 21 Nov 2018 15:49:07 +0200
Subject: [PATCH] FIX: Unassign on autoclose.


diff --git a/plugin.rb b/plugin.rb
index 5b01a2c..bd35235 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -209,8 +209,8 @@ after_initialize do
     ::TopicAssigner.auto_assign(post, force: true)
   end
 
-  on(:topic_closed) do |topic|
-    if SiteSetting.unassign_on_close
+  on(:topic_status_updated) do |topic, status|
+    if SiteSetting.unassign_on_close && (status == 'closed' || status == 'autoclosed')
       assigner = ::TopicAssigner.new(topic, Discourse.system_user)
       assigner.unassign(silent: true)
     end
diff --git a/spec/lib/topic_assigner_spec.rb b/spec/lib/topic_assigner_spec.rb
index 9091d5e..0287137 100644
--- a/spec/lib/topic_assigner_spec.rb
+++ b/spec/lib/topic_assigner_spec.rb
@@ -82,4 +82,28 @@ RSpec.describe TopicAssigner do
     end
 
   end
+
+  context "unassign_on_close" do
+    let(:post) { Fabricate(:post) }
+    let(:topic) { post.topic }
+    let(:moderator) { Fabricate(:moderator) }
+    let(:assigner) { TopicAssigner.new(topic, moderator) }
+
+    before do
+      SiteSetting.assign_enabled = true
+      SiteSetting.unassign_on_close = true
+
+      assigner.assign(moderator)
+    end
+
+    it "will unassign on topic closed" do
+      topic.update_status("closed", true, moderator)
+      expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to be_blank
+    end
+
+    it "will unassign on topic autoclosed" do
+      topic.update_status("autoclosed", true, moderator)
+      expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to be_blank
+    end
+  end
 end

GitHub

2 Likes