omit single quotes from slug

This commit is contained in:
Sam 2013-06-03 09:08:34 +10:00
parent 1833c124d9
commit da22c0f359
2 changed files with 6 additions and 4 deletions

View file

@ -1,12 +1,10 @@
# encoding: utf-8 # encoding: utf-8
# Generates a slug. This is annoying because it's duplicating what the javascript
# does, but on the other hand slugs are never matched so it's okay if they differ
# a little.
module Slug module Slug
def self.for(string) def self.for(string)
slug = string.parameterize.gsub("_", "-") slug = string.gsub("'", "").parameterize
slug.gsub!("_", "-")
slug =~ /[^\d]/ ? slug : '' # Reject slugs that only contain numbers, because they would be indistinguishable from id's. slug =~ /[^\d]/ ? slug : '' # Reject slugs that only contain numbers, because they would be indistinguishable from id's.
end end

View file

@ -51,5 +51,9 @@ describe Slug do
Slug.for('電車男 2').should be_blank Slug.for('電車男 2').should be_blank
end end
it "doesn't keep single quotes within word" do
Slug.for("Jeff hate's this").should == "jeff-hates-this"
end
end end