support setting category slug

This commit is contained in:
Erick Guan
2014-12-20 22:07:29 +08:00
parent 1055fc0919
commit 1e166d89ff
11 changed files with 92 additions and 15 deletions

View File

@@ -203,4 +203,42 @@ describe CategoriesController do
end
describe 'update_slug' do
it 'requires the user to be logged in' do
lambda { xhr :put, :update_slug, category_id: 'category'}.should raise_error(Discourse::NotLoggedIn)
end
describe 'logged in' do
let(:valid_attrs) { {id: @category.id, slug: 'fff'} }
before do
@user = log_in(:admin)
@category = Fabricate(:happy_category, user: @user)
end
it 'rejects blank' do
xhr :put, :update_slug, category_id: @category.id, slug: nil
response.status.should == 422
end
it 'accepts valid custom slug' do
xhr :put, :update_slug, category_id: @category.id, slug: 'valid-slug'
response.should be_success
category = Category.find(@category.id)
category.slug.should == 'valid-slug'
end
it 'accepts not well formed custom slug' do
xhr :put, :update_slug, category_id: @category.id, slug: ' valid slug'
response.should be_success
category = Category.find(@category.id)
category.slug.should == 'valid-slug'
end
it 'rejects invalid custom slug' do
xhr :put, :update_slug, category_id: @category.id, slug: ' '
response.status.should == 422
end
end
end
end

View File

@@ -7,3 +7,9 @@ Fabricator(:diff_category, from: :category) do
name "Different Category"
user
end
Fabricator(:happy_category, from: :category) do
name 'Happy Category'
slug 'happy'
user
end

View File

@@ -198,6 +198,11 @@ describe Category do
c.slug.should eq("cats-category")
end
it 'and be sanitized' do
c = Fabricate(:category, name: 'Cats', slug: ' invalid slug')
c.slug.should == 'invalid-slug'
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")