diff --git a/app/models/category.rb b/app/models/category.rb index 0d95aed02..e09e40315 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 ef7b5e7d6..c14d5982d 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