From 309834fa82c16e1be06e0af158b133b6d4940644 Mon Sep 17 00:00:00 2001 From: Aleksey V Zapparov Date: Tue, 9 Aug 2011 02:10:51 +0200 Subject: [PATCH] Resolves issue#78 --- lib/ext/ext.rb | 2 +- test/toto_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ext/ext.rb b/lib/ext/ext.rb index c3b2cdd..3b71270 100644 --- a/lib/ext/ext.rb +++ b/lib/ext/ext.rb @@ -8,7 +8,7 @@ def meta_def name, &blk class String def slugize - self.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '') + self.downcase.gsub(/&/, 'and').gsub(/[^a-z0-9-]+/, '-').gsub(/^-|-$/, '') end def humanize diff --git a/test/toto_test.rb b/test/toto_test.rb index aa090b6..9b6d913 100644 --- a/test/toto_test.rb +++ b/test/toto_test.rb @@ -200,6 +200,16 @@ def readme() "#{self[:name]}'s README" end should("create a valid summary") { topic.summary.size }.within 75..80 end + + context "all non-alphanumeric characters" do + setup do + Toto::Article.new({ + :title => "Having fun with //Applescript/Bananascript// and Terminal.app///" + }, @config) + end + + should("be replaced with single dash") { topic.slug }.equals "having-fun-with-applescript-bananascript-and-terminal-app" + end end context "in a subdirectory" do