diff --git a/app/models/category.rb b/app/models/category.rb index c03972bfa02..be7443ffe97 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -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 diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index 988505fe443..4ef85e07898 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -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