Skip to content

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

FIX: Auto re-opened topics should restore category auto close settings.

Guo Xiang Tan486bbe9cc280
diff --git a/app/jobs/regular/toggle_topic_closed.rb b/app/jobs/regular/toggle_topic_closed.rb
index dab5d65190e..7a77f024896 100644
--- a/app/jobs/regular/toggle_topic_closed.rb
+++ b/app/jobs/regular/toggle_topic_closed.rb
@@ -16,6 +16,7 @@ module Jobs
if Guardian.new(user).can_close?(topic)
topic.update_status('autoclosed', state, user)
+ topic.inherit_auto_close_from_category if state == false
end
end
end
diff --git a/spec/jobs/toggle_topic_closed_spec.rb b/spec/jobs/toggle_topic_closed_spec.rb
index 2e36f8abaa8..c05b2950da4 100644
--- a/spec/jobs/toggle_topic_closed_spec.rb
+++ b/spec/jobs/toggle_topic_closed_spec.rb
@@ -28,20 +28,49 @@ describe Jobs::ToggleTopicClosed do
end
end
- it 'should be able to open a topic' do
- topic.update!(closed: true)
+ describe 'opening a topic' do
+ it 'should be work' do
+ topic.update!(closed: true)
+
+ freeze_time(1.hour.from_now) do
+ described_class.new.execute(
+ topic_timer_id: topic.public_topic_timer.id,
+ state: false
+ )
+
+ expect(topic.reload.closed).to eq(false)
+
+ expect(Post.last.raw).to eq(I18n.t(
+ 'topic_statuses.autoclosed_disabled_minutes', count: 60
+ ))
+ end
+ end
- freeze_time(1.hour.from_now) do
- described_class.new.execute(
- topic_timer_id: topic.public_topic_timer.id,
- state: false
- )
+ describe 'when category has auto close configured' do
+ let(:category) { Fabricate(:category, auto_close_hours: 5) }
+ let(:topic) { Fabricate(:topic, category: category, closed: true) }
- expect(topic.reload.closed).to eq(false)
+ it "should restore the category's auto close timer" do
+ Fabricate(:topic_timer,
+ status_type: TopicTimer.types[:open],
+ topic: topic,
+ user: admin
+ )
- expect(Post.last.raw).to eq(I18n.t(
- 'topic_statuses.autoclosed_disabled_minutes', count: 60
- ))
+ freeze_time(1.hour.from_now) do
+ described_class.new.execute(
+ topic_timer_id: topic.public_topic_timer.id,
+ state: false
+ )
+
+ expect(topic.reload.closed).to eq(false)
+
+ topic_timer = topic.public_topic_timer
+
+ expect(topic_timer.status_type).to eq(TopicTimer.types[:close])
+ expect(topic_timer.execute_at).to eq(5.hours.from_now)
+ end
+ end
end
end