mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
support setting category slug
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user