FIX: Allow duplicate slugs when the parent category is not the same

This commit is contained in:
Robin Ward 2014-08-13 14:45:25 -04:00
parent 3c6673aceb
commit 74d9293ca9
2 changed files with 9 additions and 2 deletions

View File

@ -187,7 +187,7 @@ SQL
# If a category with that slug already exists, set the slug to nil so the category can be found
# another way.
category = Category.where(slug: self.slug)
category = Category.where(slug: self.slug, parent_category_id: parent_category_id)
category = category.where("id != ?", id) if id.present?
self.slug = '' if category.exists?
end

View File

@ -243,11 +243,18 @@ describe Category do
end
describe "creating a new category with the same slug" do
it "should have a blank slug" do
it "should have a blank slug if at the same level" do
category = Fabricate(:category, name: "Amazing Categóry")
category.slug.should be_blank
category.slug_for_url.should == "#{category.id}-category"
end
it "doesn't have a blank slug if not at the same level" do
parent = Fabricate(:category, name: 'Other parent')
category = Fabricate(:category, name: "Amazing Categóry", parent_category_id: parent.id)
category.slug.should == 'amazing-category'
category.slug_for_url.should == "amazing-category"
end
end
describe "trying to change the category topic's category" do