Skip to content

A platform for community discussion. Free, open, simple.

FIX: Topics should honor auto-close when published to category (#8963)

tshenrya09e5d12c23f
diff --git a/app/jobs/regular/publish_topic_to_category.rb b/app/jobs/regular/publish_topic_to_category.rb
index 1b86fc90342..79df028007c 100644
--- a/app/jobs/regular/publish_topic_to_category.rb
+++ b/app/jobs/regular/publish_topic_to_category.rb
@@ -12,6 +12,8 @@ module Jobs
TopicTimer.transaction do
TopicPublisher.new(topic, Discourse.system_user, topic_timer.category_id).publish!
end
+
+ Topic.find(topic.id).inherit_auto_close_from_category
end
end
end
diff --git a/spec/jobs/publish_topic_to_category_spec.rb b/spec/jobs/publish_topic_to_category_spec.rb
index 4b9a526b12c..3602eaa5b3e 100644
--- a/spec/jobs/publish_topic_to_category_spec.rb
+++ b/spec/jobs/publish_topic_to_category_spec.rb
@@ -84,4 +84,22 @@ RSpec.describe Jobs::PublishTopicToCategory do
expect(message.data[:refresh_stream]).to be_present
end
end
+
+ describe 'when new category has a default auto-close' do
+ before do
+ another_category.update!(auto_close_hours: 5)
+ end
+
+ it 'should apply the auto-close timer upon publishing' do
+ topic
+
+ described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
+
+ topic.reload
+ topic_timer = topic.public_topic_timer
+ expect(topic.category).to eq(another_category)
+ expect(topic_timer.status_type).to eq(TopicTimer.types[:close])
+ expect(topic_timer.execute_at).to be_within(1.second).of(5.hours.from_now)
+ end
+ end
end