If an auto-closing topic is manually closed, remove the auto-close countdown

This commit is contained in:
Neil Lalonde 2013-07-03 16:44:45 -04:00
parent 44cd5505d3
commit 2c8ed8414c
3 changed files with 20 additions and 6 deletions

View file

@ -138,7 +138,7 @@ class Topic < ActiveRecord::Base
before_save do
if (auto_close_at_changed? and !auto_close_at_was.nil?) or (auto_close_user_id_changed? and auto_close_at)
self.auto_close_started_at ||= Time.zone.now
self.auto_close_started_at ||= Time.zone.now if auto_close_at
Jobs.cancel_scheduled_job(:close_topic, {topic_id: id})
true
end

View file

@ -18,6 +18,10 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
else
topic.update_column status.name, status.enabled?
end
if status.manually_closing_topic? && topic.auto_close_at
topic.reload.set_auto_close(nil).save
end
end
def create_moderator_post_for(status)
@ -57,5 +61,9 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
def reopening_topic?
(closed? || autoclosed?) && disabled?
end
def manually_closing_topic?
closed? && enabled?
end
end
end

View file

@ -60,6 +60,12 @@ describe Topic do
Given(:admin) { Fabricate(:admin) }
Given(:staff_topic) { Fabricate(:topic, user: admin, category: category) }
Then { scheduled_jobs_for(:close_topic, {topic_id: staff_topic.id, user_id: admin.id}).should have(1).job }
context 'topic is closed manually' do
When { staff_topic.update_status('closed', true, admin) }
Then { staff_topic.reload.auto_close_at.should be_nil }
And { staff_topic.auto_close_started_at.should be_nil }
end
end
context 'topic was created by a non-staff user' do