FIX: Unassign on autoclose.

This commit is contained in:
Bianca Nenciu 2018-11-21 15:49:07 +02:00
parent 903f1260a8
commit 0299deaf25
2 changed files with 26 additions and 2 deletions

View File

@ -209,8 +209,8 @@ after_initialize do
::TopicAssigner.auto_assign(post, force: true) ::TopicAssigner.auto_assign(post, force: true)
end end
on(:topic_closed) do |topic| on(:topic_status_updated) do |topic, status|
if SiteSetting.unassign_on_close if SiteSetting.unassign_on_close && (status == 'closed' || status == 'autoclosed')
assigner = ::TopicAssigner.new(topic, Discourse.system_user) assigner = ::TopicAssigner.new(topic, Discourse.system_user)
assigner.unassign(silent: true) assigner.unassign(silent: true)
end end

View File

@ -82,4 +82,28 @@ RSpec.describe TopicAssigner do
end end
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 end