friendly_id 3.0.6 → 3.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +10 -0
- data/Contributors.md +1 -0
- data/Guide.md +24 -35
- data/README.md +3 -3
- data/Rakefile +0 -5
- data/extras/bench.rb +5 -1
- data/extras/prof.rb +9 -4
- data/lib/friendly_id.rb +35 -7
- data/lib/friendly_id/active_record.rb +32 -17
- data/lib/friendly_id/active_record_adapter/configuration.rb +1 -0
- data/lib/friendly_id/active_record_adapter/finders.rb +136 -130
- data/lib/friendly_id/active_record_adapter/relation.rb +129 -0
- data/lib/friendly_id/active_record_adapter/simple_model.rb +2 -62
- data/lib/friendly_id/active_record_adapter/slug.rb +3 -2
- data/lib/friendly_id/active_record_adapter/slugged_model.rb +13 -145
- data/lib/friendly_id/configuration.rb +1 -1
- data/lib/friendly_id/railtie.rb +2 -2
- data/lib/friendly_id/slug_string.rb +22 -392
- data/lib/friendly_id/slugged.rb +7 -3
- data/lib/friendly_id/test.rb +1 -2
- data/lib/friendly_id/version.rb +3 -3
- data/test/active_record_adapter/ar_test_helper.rb +14 -6
- data/test/active_record_adapter/cached_slug_test.rb +10 -0
- data/test/active_record_adapter/core.rb +15 -0
- data/test/active_record_adapter/slugged.rb +0 -1
- data/test/active_record_adapter/support/models.rb +4 -0
- data/test/active_record_adapter/tasks_test.rb +1 -1
- data/test/friendly_id_test.rb +12 -16
- data/test/test_helper.rb +9 -10
- metadata +18 -16
- data/lib/friendly_id/finders.rb +0 -109
- data/test/slug_string_test.rb +0 -88
data/test/slug_string_test.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require(File.expand_path("../test_helper", __FILE__))
|
3
|
-
|
4
|
-
module FriendlyId
|
5
|
-
module Test
|
6
|
-
|
7
|
-
class SlugStringTest < ::Test::Unit::TestCase
|
8
|
-
|
9
|
-
test "should approximate ascii" do
|
10
|
-
# create string with range of Unicode"s western characters with
|
11
|
-
# diacritics, excluding the division and multiplication signs which for
|
12
|
-
# some reason or other are floating in the middle of all the letters.
|
13
|
-
s = SlugString.new((0xC0..0x17E).to_a.reject {|c| [0xD7, 0xF7].include? c}.pack("U*"))
|
14
|
-
output = s.approximate_ascii
|
15
|
-
assert(output.length > s.length)
|
16
|
-
assert_match output, /^[a-zA-Z']*$/
|
17
|
-
end
|
18
|
-
|
19
|
-
test "should strip non-word chars" do
|
20
|
-
s = SlugString.new "¡feliz año!"
|
21
|
-
assert_equal "feliz año", s.word_chars
|
22
|
-
end
|
23
|
-
|
24
|
-
test "should lowercase strings" do
|
25
|
-
assert_equal "feliz año", SlugString.new("FELIZ AÑO").downcase
|
26
|
-
end
|
27
|
-
|
28
|
-
test "should uppercase strings" do
|
29
|
-
assert_equal "FELIZ AÑO", SlugString.new("feliz año").upcase
|
30
|
-
end
|
31
|
-
|
32
|
-
test "should replace whitespace with dashes" do
|
33
|
-
assert_equal "a-b", SlugString.new("a b").clean.with_dashes
|
34
|
-
end
|
35
|
-
|
36
|
-
test "should replace multiple spaces with 1 dash" do
|
37
|
-
assert_equal "a-b", SlugString.new("a b").clean.with_dashes
|
38
|
-
end
|
39
|
-
|
40
|
-
test "should replace multiple dashes with 1 dash" do
|
41
|
-
assert_equal "male-female", SlugString.new("male - female").with_dashes
|
42
|
-
end
|
43
|
-
|
44
|
-
test "should strip trailing space" do
|
45
|
-
assert_equal "ab", SlugString.new("ab ").clean
|
46
|
-
end
|
47
|
-
|
48
|
-
test "should strip leading space" do
|
49
|
-
assert_equal "ab", SlugString.new(" ab").clean
|
50
|
-
end
|
51
|
-
|
52
|
-
test "should strip trailing slashes" do
|
53
|
-
assert_equal "ab", SlugString.new("ab-").clean
|
54
|
-
end
|
55
|
-
|
56
|
-
test "should strip leading slashes" do
|
57
|
-
assert_equal "ab", SlugString.new("-ab").clean
|
58
|
-
end
|
59
|
-
|
60
|
-
test "should not modify valid name strings" do
|
61
|
-
assert_equal "a-b-c-d", SlugString.new("a-b-c-d").clean
|
62
|
-
end
|
63
|
-
|
64
|
-
test "should do special approximations for German" do
|
65
|
-
assert_equal "Juergen", SlugString.new("Jürgen").approximate_ascii(:german)
|
66
|
-
end
|
67
|
-
|
68
|
-
test "should do special approximations for Spanish" do
|
69
|
-
assert_equal "anno", SlugString.new("año").approximate_ascii(:spanish)
|
70
|
-
end
|
71
|
-
|
72
|
-
test "should work with non roman chars" do
|
73
|
-
assert_equal "検-索", SlugString.new("検 索").with_dashes
|
74
|
-
end
|
75
|
-
|
76
|
-
test "should work with invalid UTF-8 strings" do
|
77
|
-
%w[approximate_ascii clean downcase word_chars normalize to_ascii upcase with_dashes].each do |method|
|
78
|
-
string = SlugString.new("\x93abc")
|
79
|
-
assert_nothing_raised do
|
80
|
-
method == "truncate" ? string.send(method, 32) : string.send(method)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|