mirror of
https://github.com/discourse/discourse.git
synced 2025-04-30 14:14:36 +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
|
def ensure_slug
|
||||||
if name.present?
|
if name.present?
|
||||||
|
self.name.strip!
|
||||||
self.slug = Slug.for(name)
|
self.slug = Slug.for(name)
|
||||||
|
|
||||||
return if self.slug.blank?
|
return if self.slug.blank?
|
||||||
|
@ -122,6 +122,18 @@ describe Category do
|
|||||||
end
|
end
|
||||||
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
|
describe "short name" do
|
||||||
let!(:category) { Fabricate(:category, name: 'xx') }
|
let!(:category) { Fabricate(:category, name: 'xx') }
|
||||||
|
|
||||||
@ -218,7 +230,6 @@ describe Category do
|
|||||||
@topic.category.should == @category
|
@topic.category.should == @category
|
||||||
@category.topic.should == @topic
|
@category.topic.should == @topic
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user