Skip to content

Commit abed146

Browse files
committed
FIX: Category description topics shouldn't auto-close
1 parent df7b24b commit abed146

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

app/models/category.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def self.post_template
151151
def create_category_definition
152152
t = Topic.new(title: I18n.t("category.topic_prefix", category: name), user: user, pinned_at: Time.now, category_id: id)
153153
t.skip_callbacks = true
154+
t.auto_close_days = nil
154155
t.save!
155156
update_column(:topic_id, t.id)
156157
t.posts.create(raw: post_template, user: user)

app/models/topic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ def muted?(user)
605605
# TODO: change this method, along with category's auto_close_days. Use hours.
606606
def auto_close_days=(num_days)
607607
@ignore_category_auto_close = true
608-
set_auto_close(num_days * 24)
608+
set_auto_close( num_days ? num_days * 24 : nil)
609609
end
610610

611611
def self.auto_close

spec/models/category_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@
210210
@category.topic_url.should be_present
211211
end
212212

213+
it "should not set its description topic to auto-close" do
214+
category = Fabricate(:category, name: 'Closing Topics', auto_close_days: 1)
215+
category.topic.auto_close_at.should be_nil
216+
end
217+
213218
describe "creating a new category with the same slug" do
214219
it "should have a blank slug" do
215220
Fabricate(:category, name: "Amazing Categóry").slug.should be_blank

spec/models/topic_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,22 @@ def build_topic_with_title(title)
10671067
end
10681068
end
10691069

1070+
describe "auto_close_days=" do
1071+
subject(:topic) { Fabricate.build(:topic) }
1072+
1073+
it 'can take a number' do
1074+
Timecop.freeze(Time.zone.now) do
1075+
topic.auto_close_days = 2
1076+
topic.auto_close_at.should be_within_one_second_of(2.days.from_now)
1077+
end
1078+
end
1079+
1080+
it 'can take nil' do
1081+
topic.auto_close_days = nil
1082+
topic.auto_close_at.should be_nil
1083+
end
1084+
end
1085+
10701086
describe 'set_auto_close' do
10711087
let(:topic) { Fabricate.build(:topic) }
10721088
let(:closing_topic) { Fabricate.build(:topic, auto_close_days: 5) }

0 commit comments

Comments
 (0)