mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Merge pull request #3461 from fantasticfears/slug
FIX: category custom slug can't be set when generation method is none
This commit is contained in:
commit
fdbcc31a9c
3 changed files with 15 additions and 5 deletions
|
@ -215,7 +215,7 @@ SQL
|
|||
|
||||
if slug.present?
|
||||
# santized custom slug
|
||||
self.slug = Slug.for(slug, '')
|
||||
self.slug = Slug.sanitize(slug)
|
||||
errors.add(:slug, 'is already in use') if duplicate_slug?
|
||||
else
|
||||
# auto slug
|
||||
|
|
|
@ -13,6 +13,10 @@ module Slug
|
|||
slug.blank? ? default : slug
|
||||
end
|
||||
|
||||
def self.sanitize(string)
|
||||
self.encoded_generator(string)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.ascii_generator(string)
|
||||
|
|
|
@ -232,15 +232,21 @@ describe CategoriesController do
|
|||
it 'accepts valid custom slug' do
|
||||
xhr :put, :update_slug, category_id: @category.id, slug: 'valid-slug'
|
||||
expect(response).to be_success
|
||||
category = Category.find(@category.id)
|
||||
expect(category.slug).to eq('valid-slug')
|
||||
expect(@category.reload.slug).to eq('valid-slug')
|
||||
end
|
||||
|
||||
it 'accepts not well formed custom slug' do
|
||||
xhr :put, :update_slug, category_id: @category.id, slug: ' valid slug'
|
||||
expect(response).to be_success
|
||||
category = Category.find(@category.id)
|
||||
expect(category.slug).to eq('valid-slug')
|
||||
expect(@category.reload.slug).to eq('valid-slug')
|
||||
end
|
||||
|
||||
it 'accepts and sanitize custom slug when the slug generation method is not english' do
|
||||
SiteSetting.slug_generation_method = 'none'
|
||||
xhr :put, :update_slug, category_id: @category.id, slug: ' another !_ slug @'
|
||||
expect(response).to be_success
|
||||
expect(@category.reload.slug).to eq('another-slug')
|
||||
SiteSetting.slug_generation_method = 'ascii'
|
||||
end
|
||||
|
||||
it 'rejects invalid custom slug' do
|
||||
|
|
Loading…
Reference in a new issue