discourse/spec/components/slug_spec.rb

60 lines
1.3 KiB
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05: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-12 18:53:06 -05:00
it 'replaces symbols' do
Slug.for('evil#trout').should == 'evil-trout'
2013-02-05 14:16:51 -05:00
end
2013-02-25 11:42:20 -05:00
it 'handles a.b.c properly' do
2013-02-05 14:16:51 -05:00
Slug.for("a.b.c").should == "a-b-c"
end
2013-02-25 11:42:20 -05:00
it 'handles double dots right' do
2013-02-05 14:16:51 -05:00
Slug.for("a....b.....c").should == "a-b-c"
end
it 'strips trailing punctuation' do
Slug.for("hello...").should == "hello"
end
it 'strips leading punctuation' do
Slug.for("...hello").should == "hello"
end
2013-02-05 14:16:51 -05:00
2013-02-11 21:34:38 -05:00
it 'handles our initial transliteration' do
from = "àáäâčďèéëěêìíïîľĺňòóöôŕřšťůùúüûýžñç"
to = "aaaacdeeeeeiiiillnoooorrstuuuuuyznc"
Slug.for(from).should == to
end
2013-02-14 17:46:11 -05:00
it 'replaces underscores' do
Slug.for("o_o_o").should == "o-o-o"
end
it "doesn't generate slugs that are just numbers" do
Slug.for('123').should be_blank
end
it "doesn't generate slugs that are just numbers" do
Slug.for('電車男 2').should be_blank
end
2013-06-02 19:08:34 -04:00
it "doesn't keep single quotes within word" do
Slug.for("Jeff hate's this").should == "jeff-hates-this"
end
2013-02-05 14:16:51 -05:00
end