discourse/spec/components/slug_spec.rb

65 lines
1.6 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
2015-01-09 11:34:37 -05:00
expect(Slug.for("hello world")).to eq('hello-world')
2013-02-05 14:16:51 -05:00
end
it 'changes accented characters' do
2015-01-09 11:34:37 -05:00
expect(Slug.for('àllo')).to eq('allo')
2013-02-05 14:16:51 -05:00
end
2013-02-12 18:53:06 -05:00
it 'replaces symbols' do
2015-01-09 11:34:37 -05:00
expect(Slug.for('evil#trout')).to eq('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
2015-01-09 11:34:37 -05:00
expect(Slug.for("a.b.c")).to eq("a-b-c")
2013-02-05 14:16:51 -05:00
end
2013-02-25 11:42:20 -05:00
it 'handles double dots right' do
2015-01-09 11:34:37 -05:00
expect(Slug.for("a....b.....c")).to eq("a-b-c")
2013-02-05 14:16:51 -05:00
end
it 'strips trailing punctuation' do
2015-01-09 11:34:37 -05:00
expect(Slug.for("hello...")).to eq("hello")
end
it 'strips leading punctuation' do
2015-01-09 11:34:37 -05:00
expect(Slug.for("...hello")).to eq("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"
2015-01-09 11:34:37 -05:00
expect(Slug.for(from)).to eq(to)
2013-02-11 21:34:38 -05:00
end
2013-02-14 17:46:11 -05:00
it 'replaces underscores' do
2015-01-09 11:34:37 -05:00
expect(Slug.for("o_o_o")).to eq("o-o-o")
2013-02-14 17:46:11 -05:00
end
it "doesn't generate slugs that are just numbers" do
2015-01-09 11:34:37 -05:00
expect(Slug.for('123')).to be_blank
end
it "doesn't generate slugs that are just numbers" do
2015-01-09 11:34:37 -05:00
expect(Slug.for('2')).to be_blank
end
2013-06-02 19:08:34 -04:00
it "doesn't keep single quotes within word" do
2015-01-09 11:34:37 -05:00
expect(Slug.for("Jeff hate's this")).to eq("jeff-hates-this")
2013-06-02 19:08:34 -04:00
end
it "translate the chineses" do
SiteSetting.default_locale = 'zh_CN'
2015-01-09 11:34:37 -05:00
expect(Slug.for("习近平:中企承建港口电站等助斯里兰卡发展")).to eq("xi-jin-ping-zhong-qi-cheng-jian-gang-kou-dian-zhan-deng-zhu-si-li-lan-qia-fa-zhan")
end
2013-02-05 14:16:51 -05:00
end