Strip trailing and leading spaces from category names

This commit is contained in:
Neil Lalonde 2013-07-30 16:48:19 -04:00
parent 277e4db2cb
commit 882c1524f7
2 changed files with 13 additions and 1 deletions

View File

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

View File

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