If you rename a category, also rename the category definition topic.
This commit is contained in:
parent
75f6b43e62
commit
ffa84d9bb4
|
@ -32,6 +32,7 @@ class Category < ActiveRecord::Base
|
|||
after_create :create_category_definition
|
||||
after_create :publish_categories_list
|
||||
after_destroy :publish_categories_list
|
||||
after_update :rename_category_definition, if: :name_changed?
|
||||
|
||||
has_one :category_search_data
|
||||
belongs_to :parent_category, class_name: 'Category'
|
||||
|
@ -331,6 +332,15 @@ SQL
|
|||
url << "/#{parent_category.slug}" if parent_category_id
|
||||
url << "/#{slug}"
|
||||
end
|
||||
|
||||
# If the name changes, try and update the category definition topic too if it's
|
||||
# an exact match
|
||||
def rename_category_definition
|
||||
old_name = changed_attributes["name"]
|
||||
if topic.title == I18n.t("category.topic_prefix", category: old_name)
|
||||
topic.update_column(:title, I18n.t("category.topic_prefix", category: name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -220,6 +220,12 @@ describe Category do
|
|||
@category.topics_year.should == 0
|
||||
end
|
||||
|
||||
it "renames the definition when renamed" do
|
||||
@category.update_attributes(name: 'Troutfishing')
|
||||
@topic.reload
|
||||
@topic.title.should =~ /Troutfishing/
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue