diff --git a/app/models/topic.rb b/app/models/topic.rb index e5787076900..2dd51661d25 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -216,7 +216,8 @@ class Topic < ActiveRecord::Base end def inherit_auto_close_from_category - if !@ignore_category_auto_close && + if !self.closed && + !@ignore_category_auto_close && self.category && self.category.auto_close_hours && !public_topic_timer&.execute_at @@ -1010,7 +1011,7 @@ SQL topic_timer.status_type = status_type if time.blank? - topic_timer.trash!(trashed_by: by_user || Discourse.system_user) + topic_timer.trash!(by_user || Discourse.system_user) return end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index a1d5334fce6..6dbcbdd340a 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1066,6 +1066,21 @@ describe Topic do expect(topic_timer.execute_at).to be_within(1.second).of(Time.zone.now + 5.hours) end + describe 'when topic is already closed' do + before do + SiteSetting.queue_jobs = true + topic.update_status('closed', true, Discourse.system_user) + end + + it 'should not set a topic timer' do + expect { topic.change_category_to_id(new_category.id) } + .to change { TopicTimer.with_deleted.count }.by(0) + + expect(topic.closed).to eq(true) + expect(topic.reload.category).to eq(new_category) + end + end + describe 'when topic has an existing topic timer' do let(:topic_timer) { Fabricate(:topic_timer, topic: topic) }