mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 05:52:49 +08:00
Strip trailing and leading spaces from category names
This commit is contained in:
parent
277e4db2cb
commit
882c1524f7
|
@ -121,6 +121,7 @@ class Category < ActiveRecord::Base
|
|||
|
||||
def ensure_slug
|
||||
if name.present?
|
||||
self.name.strip!
|
||||
self.slug = Slug.for(name)
|
||||
|
||||
return if self.slug.blank?
|
||||
|
|
|
@ -122,6 +122,18 @@ describe Category do
|
|||
end
|
||||
end
|
||||
|
||||
it "strips leading blanks" do
|
||||
Fabricate(:category, name: " music").name.should == "music"
|
||||
end
|
||||
|
||||
it "strips trailing blanks" do
|
||||
Fabricate(:category, name: "bugs ").name.should == "bugs"
|
||||
end
|
||||
|
||||
it "strips leading and trailing blanks" do
|
||||
Fabricate(:category, name: " blanks ").name.should == "blanks"
|
||||
end
|
||||
|
||||
describe "short name" do
|
||||
let!(:category) { Fabricate(:category, name: 'xx') }
|
||||
|
||||
|
@ -218,7 +230,6 @@ describe Category do
|
|||
@topic.category.should == @category
|
||||
@category.topic.should == @topic
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user