discourse/spec/components/slug_spec.rb

65 lines
1.6 KiB
Ruby
Raw Normal View History

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
2015-01-10 00:34:37 +08:00
expect(Slug.for("hello world")).to eq('hello-world')
2013-02-06 03:16:51 +08:00
end
it 'changes accented characters' do
2015-01-10 00:34:37 +08:00
expect(Slug.for('àllo')).to eq('allo')
2013-02-06 03:16:51 +08:00
end
2013-02-13 07:53:06 +08:00
it 'replaces symbols' do
2015-01-10 00:34:37 +08:00
expect(Slug.for('evil#trout')).to eq('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
2015-01-10 00:34:37 +08:00
expect(Slug.for("a.b.c")).to eq("a-b-c")
2013-02-06 03:16:51 +08:00
end
2013-02-26 00:42:20 +08:00
it 'handles double dots right' do
2015-01-10 00:34:37 +08:00
expect(Slug.for("a....b.....c")).to eq("a-b-c")
2013-02-06 03:16:51 +08:00
end
it 'strips trailing punctuation' do
2015-01-10 00:34:37 +08:00
expect(Slug.for("hello...")).to eq("hello")
end
it 'strips leading punctuation' do
2015-01-10 00:34:37 +08:00
expect(Slug.for("...hello")).to eq("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"
2015-01-10 00:34:37 +08:00
expect(Slug.for(from)).to eq(to)
2013-02-12 10:34:38 +08:00
end
2013-02-15 06:46:11 +08:00
it 'replaces underscores' do
2015-01-10 00:34:37 +08:00
expect(Slug.for("o_o_o")).to eq("o-o-o")
2013-02-15 06:46:11 +08:00
end
it "doesn't generate slugs that are just numbers" do
2015-01-10 00:34:37 +08:00
expect(Slug.for('123')).to be_blank
end
it "doesn't generate slugs that are just numbers" do
2015-01-10 00:34:37 +08:00
expect(Slug.for('2')).to be_blank
end
2013-06-03 07:08:34 +08:00
it "doesn't keep single quotes within word" do
2015-01-10 00:34:37 +08:00
expect(Slug.for("Jeff hate's this")).to eq("jeff-hates-this")
2013-06-03 07:08:34 +08:00
end
it "translate the chineses" do
SiteSetting.default_locale = 'zh_CN'
2015-01-10 00:34:37 +08: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-06 03:16:51 +08:00
end