From 6ba5f715f3961e624ab64af8a58ef50b70d20977 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 25 Jul 2014 16:36:16 -0400 Subject: [PATCH] FIX: There was an error renaming the Uncategorized topic --- app/models/category.rb | 1 + spec/models/category_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/models/category.rb b/app/models/category.rb index 0d95aed02bc..e09e40315b5 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -337,6 +337,7 @@ SQL # an exact match def rename_category_definition old_name = changed_attributes["name"] + return unless topic.present? if topic.title == I18n.t("category.topic_prefix", category: old_name) topic.update_column(:title, I18n.t("category.topic_prefix", category: name)) end diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index ef7b5e7d623..c14d5982d4d 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -226,6 +226,10 @@ describe Category do @topic.title.should =~ /Troutfishing/ end + it "doesn't raise an error if there is no definition topic to rename (uncategorized)" do + -> { @category.update_attributes(name: 'Troutfishing', topic_id: nil) }.should_not raise_error + end + it "should not set its description topic to auto-close" do category = Fabricate(:category, name: 'Closing Topics', auto_close_hours: 1) category.topic.auto_close_at.should be_nil