From da22c0f359b38041d38b58fa0fa93b491b194d52 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 3 Jun 2013 09:08:34 +1000 Subject: [PATCH] omit single quotes from slug --- lib/slug.rb | 6 ++---- spec/components/slug_spec.rb | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/slug.rb b/lib/slug.rb index f44bce6fe..d30833cb1 100644 --- a/lib/slug.rb +++ b/lib/slug.rb @@ -1,12 +1,10 @@ # 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 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. end diff --git a/spec/components/slug_spec.rb b/spec/components/slug_spec.rb index 3c5d23cbc..6491b3002 100644 --- a/spec/components/slug_spec.rb +++ b/spec/components/slug_spec.rb @@ -51,5 +51,9 @@ describe Slug do Slug.for('電車男 2').should be_blank end + it "doesn't keep single quotes within word" do + Slug.for("Jeff hate's this").should == "jeff-hates-this" + end + end