forked from xaviershay/enki
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
String#slugorize now allows apostrophes, and correctly strips multiple
dashes at the start and end of the string.
- Loading branch information
1 parent
4bdb37c
commit 98cfaff
Showing
2 changed files
with
33 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
describe String do | ||
describe String, '#slugorize' do | ||
it "should lowercase everything" do | ||
"ABCDEF".slugorize.should == "abcdef" | ||
end | ||
|
||
it "should leave alphanumerics and hyphens alone" do | ||
"abc-123".slugorize.should == "abc-123" | ||
end | ||
|
||
it "should ditch entities" do | ||
"abc<-<xyz".slugorize.should == "abc-xyz" | ||
end | ||
|
||
it "should replace & with and" do | ||
"a-&-b-&-c".slugorize.should == "a-and-b-and-c" | ||
end | ||
|
||
it "should strip all non-alphanumeric characters except - and &" do | ||
'abc\'""!@#$%^*()/=+|\[],.<>123'.slugorize.should == "abc-123" | ||
'abc""!@#$%^*()/=+|\[],.<>123'.slugorize.should == "abc-123" | ||
end | ||
|
||
it "should allow apostrophes for good punctuation" do | ||
"tomato's".slugorize.should == "tomato's" | ||
end | ||
|
||
it "should replace all whitespace with a dash" do | ||
"abc\n\t xyz".slugorize.should == "abc-xyz" | ||
end | ||
|
||
it "should trim dashes at the tail" do | ||
"abc-".slugorize.should == "abc" | ||
"abc--".slugorize.should == "abc" | ||
end | ||
|
||
it "should trim dashes at the head" do | ||
"-abc".slugorize.should == "abc" | ||
"--abc".slugorize.should == "abc" | ||
end | ||
|
||
it "should collapse multiple dashes" do | ||
"abc---xyz".slugorize.should == "abc-xyz" | ||
end | ||
end | ||
|