Merge pull request #3021 from jmay/custom-category-slug

optional custom value for category slug (create and update)
This commit is contained in:
Robin Ward
2014-12-29 10:34:23 -05:00
4 changed files with 43 additions and 12 deletions

View File

@@ -192,6 +192,20 @@ describe Category do
end
end
describe 'custom slug can be provided' do
it 'has the custom value' do
c = Fabricate(:category, name: "Cats", slug: "cats-category")
c.slug.should eq("cats-category")
end
it 'fails if custom slug is duplicate with existing' do
c1 = Fabricate(:category, name: "Cats", slug: "cats")
c2 = Fabricate.build(:category, name: "More Cats", slug: "cats")
c2.should_not be_valid
c2.errors[:slug].should be_present
end
end
describe 'description_text' do
it 'correctly generates text description as needed' do
c = Category.new
@@ -284,6 +298,16 @@ describe Category do
end
end
describe "update" do
it "should enforce uniqueness of slug" do
Fabricate(:category, slug: "the-slug")
c2 = Fabricate(:category, slug: "different-slug")
c2.slug = "the-slug"
c2.should_not be_valid
c2.errors[:slug].should be_present
end
end
describe 'destroy' do
before do
@category = Fabricate(:category)