remove leading and trailing underscores from title_as_url

This commit is contained in:
joshua stein 2012-07-02 11:12:24 -05:00
parent 4a221aa2d3
commit 6258cb7f75
2 changed files with 6 additions and 1 deletions

View file

@ -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 = "/")

View file

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