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:
Sam 2015-05-15 14:59:35 +10:00
commit fdbcc31a9c
3 changed files with 15 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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