From abed146cc709dbb0a6465422ad9970f7f630c4db Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 3 Dec 2013 18:53:40 -0500 Subject: [PATCH] FIX: Category description topics shouldn't auto-close --- app/models/category.rb | 1 + app/models/topic.rb | 2 +- spec/models/category_spec.rb | 5 +++++ spec/models/topic_spec.rb | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/models/category.rb b/app/models/category.rb index c44db4cb91d..b5b32cf9d68 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -151,6 +151,7 @@ SQL def create_category_definition t = Topic.new(title: I18n.t("category.topic_prefix", category: name), user: user, pinned_at: Time.now, category_id: id) t.skip_callbacks = true + t.auto_close_days = nil t.save! update_column(:topic_id, t.id) t.posts.create(raw: post_template, user: user) diff --git a/app/models/topic.rb b/app/models/topic.rb index 301c8340086..6de61038136 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -605,7 +605,7 @@ class Topic < ActiveRecord::Base # TODO: change this method, along with category's auto_close_days. Use hours. def auto_close_days=(num_days) @ignore_category_auto_close = true - set_auto_close(num_days * 24) + set_auto_close( num_days ? num_days * 24 : nil) end def self.auto_close diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index 10867eab747..0ad7272279e 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -210,6 +210,11 @@ describe Category do @category.topic_url.should be_present end + it "should not set its description topic to auto-close" do + category = Fabricate(:category, name: 'Closing Topics', auto_close_days: 1) + category.topic.auto_close_at.should be_nil + end + describe "creating a new category with the same slug" do it "should have a blank slug" do Fabricate(:category, name: "Amazing Categóry").slug.should be_blank diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index e4055793db4..ba0944fc3f1 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1067,6 +1067,22 @@ describe Topic do end end + describe "auto_close_days=" do + subject(:topic) { Fabricate.build(:topic) } + + it 'can take a number' do + Timecop.freeze(Time.zone.now) do + topic.auto_close_days = 2 + topic.auto_close_at.should be_within_one_second_of(2.days.from_now) + end + end + + it 'can take nil' do + topic.auto_close_days = nil + topic.auto_close_at.should be_nil + end + end + describe 'set_auto_close' do let(:topic) { Fabricate.build(:topic) } let(:closing_topic) { Fabricate.build(:topic, auto_close_days: 5) }