2013-02-06 03:16:51 +08:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require 'slug'
|
|
|
|
|
|
|
|
describe Slug do
|
|
|
|
|
|
|
|
it 'replaces spaces with hyphens' do
|
|
|
|
Slug.for("hello world").should == 'hello-world'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'changes accented characters' do
|
|
|
|
Slug.for('àllo').should == 'allo'
|
|
|
|
end
|
|
|
|
|
2013-02-13 07:53:06 +08:00
|
|
|
it 'replaces symbols' do
|
|
|
|
Slug.for('evil#trout').should == 'evil-trout'
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
it 'handles a.b.c properly' do
|
2013-02-06 03:16:51 +08:00
|
|
|
Slug.for("a.b.c").should == "a-b-c"
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
it 'handles double dots right' do
|
2013-02-06 03:16:51 +08:00
|
|
|
Slug.for("a....b.....c").should == "a-b-c"
|
|
|
|
end
|
|
|
|
|
2013-02-07 09:52:14 +08:00
|
|
|
it 'strips trailing punctuation' do
|
|
|
|
Slug.for("hello...").should == "hello"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'strips leading punctuation' do
|
|
|
|
Slug.for("...hello").should == "hello"
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2013-02-12 10:34:38 +08:00
|
|
|
it 'handles our initial transliteration' do
|
|
|
|
from = "àáäâčďèéëěêìíïîľĺňòóöôŕřšťůùúüûýžñç"
|
|
|
|
to = "aaaacdeeeeeiiiillnoooorrstuuuuuyznc"
|
|
|
|
Slug.for(from).should == to
|
|
|
|
end
|
|
|
|
|
2013-02-15 06:46:11 +08:00
|
|
|
it 'replaces underscores' do
|
|
|
|
Slug.for("o_o_o").should == "o-o-o"
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|