diff --git a/app/models/story.rb b/app/models/story.rb index a88eef7..1780261 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -180,7 +180,7 @@ class Story < ActiveRecord::Base while u.match(/__/) u.gsub!("__", "_") end - u + u.gsub(/^_+/, "").gsub(/_+$/, "") end def url_or_comments_url(root_url = "/") diff --git a/spec/models/story_spec.rb b/spec/models/story_spec.rb index 8069fcf..9b318da 100644 --- a/spec/models/story_spec.rb +++ b/spec/models/story_spec.rb @@ -93,4 +93,9 @@ describe Story do "spec/fixtures/story_pages/2.html") s.fetched_title.should == "Google" end + + it "has an underscored url from its title" do + s = Story.make(:title => "The One-second War (What Time Will You Die?) ") + s.title_as_url.should == "the_one-second_war_what_time_will_you_die" + end end