friendly_id 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/History.txt +10 -0
- data/Manifest.txt +5 -18
- data/Rakefile +7 -10
- data/friendly_id.gemspec +17 -8
- data/lib/friendly_id.rb +29 -13
- data/lib/friendly_id/non_sluggable_class_methods.rb +4 -4
- data/lib/friendly_id/non_sluggable_instance_methods.rb +8 -0
- data/lib/friendly_id/slug.rb +14 -12
- data/lib/friendly_id/sluggable_class_methods.rb +13 -2
- data/lib/friendly_id/sluggable_instance_methods.rb +8 -5
- data/lib/friendly_id/version.rb +1 -1
- data/test/{fixtures → models}/country.rb +0 -0
- data/test/{fixtures → models}/person.rb +0 -0
- data/test/models/post.rb +3 -0
- data/test/{fixtures → models}/user.rb +0 -0
- data/test/non_slugged_test.rb +65 -60
- data/test/schema.rb +18 -18
- data/test/scoped_model_test.rb +43 -13
- data/test/slug_test.rb +93 -74
- data/test/slugged_model_test.rb +263 -0
- data/test/test_helper.rb +27 -29
- metadata +41 -24
- metadata.gz.sig +1 -2
- data/lib/friendly_id/shoulda_macros.rb +0 -36
- data/test/database.yml +0 -3
- data/test/fixtures/countries.yml +0 -4
- data/test/fixtures/people.yml +0 -7
- data/test/fixtures/post.rb +0 -3
- data/test/fixtures/posts.yml +0 -23
- data/test/fixtures/slugs.yml +0 -53
- data/test/fixtures/users.yml +0 -7
- data/test/rails/2.x/app/controllers/application.rb +0 -0
- data/test/rails/2.x/config/boot.rb +0 -109
- data/test/rails/2.x/config/database.yml +0 -3
- data/test/rails/2.x/config/environment.rb +0 -7
- data/test/rails/2.x/config/environments/test.rb +0 -6
- data/test/rails/2.x/config/routes.rb +0 -0
- data/test/sluggable_test.rb +0 -185
@@ -1,6 +0,0 @@
|
|
1
|
-
config.cache_classes = true
|
2
|
-
config.whiny_nils = true
|
3
|
-
config.action_controller.consider_all_requests_local = true
|
4
|
-
config.action_controller.perform_caching = false
|
5
|
-
config.action_controller.allow_forgery_protection = false
|
6
|
-
config.action_mailer.delivery_method = :test
|
File without changes
|
data/test/sluggable_test.rb
DELETED
@@ -1,185 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class SluggableTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
fixtures :posts, :slugs
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Post.friendly_id_options[:max_length] = FriendlyId::ClassMethods::DEFAULT_FRIENDLY_ID_OPTIONS[:max_length]
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_should_allow_for_identical_slug_names_between_sluggable_types
|
12
|
-
assert !Post.find(slugs(:post_with_same_friendly_id_as_person).name).has_better_id?
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_class_should_have_friendly_id_options
|
16
|
-
assert_not_nil Post.friendly_id_options
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_should_generate_slug_text
|
20
|
-
@post = Post.new(:name => "Test post", :content => "Test content")
|
21
|
-
assert_equal "test-post", @post.slug_text
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_save_slug_when_creating
|
25
|
-
@post = Post.create(:name => "Test post", :content => "Test content")
|
26
|
-
assert @post.slug
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_to_param_should_always_return_a_string
|
30
|
-
assert_equal String, posts(:without_slug).to_param.class
|
31
|
-
assert_equal String, posts(:with_one_slug).to_param.class
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_finder_options_are_not_ignored
|
35
|
-
assert_raises ActiveRecord::RecordNotFound do
|
36
|
-
Post.find(slugs(:one).name, :conditions => "1 = 2")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_should_still_be_able_to_find_record_by_id
|
41
|
-
post = Post.create!(:name => "New post")
|
42
|
-
Post.create!(:name => "#{post.id.to_s} and some text")
|
43
|
-
assert_equal post, Post.find(post.id)
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
def test_should_not_be_found_using_friendly_id_by_default
|
48
|
-
@post = Post.new
|
49
|
-
assert !@post.found_using_friendly_id?
|
50
|
-
assert @post.found_using_numeric_id?
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_should_be_using_friendly_id_when_find_arg_is_an_array
|
54
|
-
@posts = Post.find([posts(:with_one_slug).friendly_id, posts(:with_two_slugs).friendly_id])
|
55
|
-
assert @posts.all? { |post| post.found_using_friendly_id? }
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_raises_active_record_not_found_when_not_all_records_found
|
59
|
-
assert_raises(ActiveRecord::RecordNotFound) do
|
60
|
-
Post.find([posts(:with_one_slug).slug.name, 'non-existant-slug-record'])
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_should_indicate_if_it_was_found_using_numeric_id
|
65
|
-
@post = Post.find(posts(:with_two_slugs).id)
|
66
|
-
assert @post.found_using_numeric_id?
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_post_should_indicate_if_it_was_found_using_friendly_id
|
70
|
-
@post = Post.find(posts(:with_two_slugs).slug.name)
|
71
|
-
assert @post.found_using_friendly_id?
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_post_should_indicate_if_it_was_found_using_outdated_friendly_id
|
75
|
-
@post = Post.find(posts(:with_two_slugs).slugs.last.name)
|
76
|
-
assert @post.found_using_outdated_friendly_id?
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_should_indicate_there_is_a_better_id_if_found_by_numeric_id
|
80
|
-
@post = Post.find(posts(:with_one_slug).id)
|
81
|
-
assert @post.has_better_id?
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_should_indicate_there_is_a_better_id_if_found_by_outdated_friendly_id
|
85
|
-
@post = Post.find(posts(:with_two_slugs).slugs.last.name)
|
86
|
-
assert @post.has_better_id?
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_slug_should_always_be_the_most_recent
|
90
|
-
@post = Post.find(posts(:with_two_slugs).slug.name)
|
91
|
-
assert !@post.has_better_id?
|
92
|
-
assert slugs(:two_new).name, @post.slug.name
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_should_strip_diactics_from_slug_if_configured_to_do_so
|
96
|
-
Post.friendly_id_options[:strip_diacritics] = true
|
97
|
-
@post = Post.new(:name => "¡FELIZ AÑO!")
|
98
|
-
# Happy anus to you too
|
99
|
-
assert_equal "feliz-ano", @post.slug_text
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_should_not_strip_diactics_from_slug_unless_configured_to_do_so
|
103
|
-
Post.friendly_id_options[:strip_diacritics] = false
|
104
|
-
@post = Post.new(:name => "¡FELIZ AÑO!")
|
105
|
-
assert_equal "feliz-año", @post.slug_text
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_should_not_make_new_slug_unless_friendly_id_method_has_changed
|
109
|
-
posts(:with_one_slug).content = "Edited content"
|
110
|
-
posts(:with_one_slug).save!
|
111
|
-
assert_equal 1, posts(:with_one_slug).slugs.size
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_post_should_make_new_slug_if_friendly_id_method_is_changed
|
115
|
-
posts(:with_one_slug).name = "Edited name"
|
116
|
-
posts(:with_one_slug).save!
|
117
|
-
assert_equal 2, posts(:with_one_slug).slugs.size
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_should_increment_sequence_for_duplicate_slugs
|
121
|
-
@post = Post.create!(:name => slugs(:one).name, :content => "stuff")
|
122
|
-
assert_equal 2, @post.slug.sequence
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_friendly_id_should_contain_sequence_unless_its_1
|
126
|
-
@post = Post.create!(:name => slugs(:one).name, :content => "stuff")
|
127
|
-
assert_equal "#{slugs(:one).name}--2", @post.friendly_id
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_should_truncate_slugs_longer_than_maxlength
|
131
|
-
Post.friendly_id_options[:max_length] = 10
|
132
|
-
@post = Post.new(:name => "x" * 11, :content => "Test content")
|
133
|
-
assert @post.slug_text.length <= Post.friendly_id_options[:max_length]
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_should_ensure_truncated_slugs_that_collide_have_different_sequences
|
137
|
-
Post.friendly_id_options[:max_length] = 2
|
138
|
-
p = Post.create!(:name => "aaa")
|
139
|
-
q = Post.create!(:name => "aaab")
|
140
|
-
assert_not_equal p.friendly_id, q.friendly_id
|
141
|
-
assert_equal p.slug.name, q.slug.name
|
142
|
-
assert_not_equal p.slug.sequence, q.slug.sequence
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_should_be_able_to_rename_back_to_old_friendly_id
|
146
|
-
p = Post.create!(:name => "value")
|
147
|
-
assert_equal "value", p.friendly_id
|
148
|
-
p.name = "different value"
|
149
|
-
p.save!
|
150
|
-
p.reload
|
151
|
-
assert_equal "different-value", p.friendly_id
|
152
|
-
p.name = "value"
|
153
|
-
assert p.save!
|
154
|
-
p.reload
|
155
|
-
assert_equal "value", p.friendly_id
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_should_raise_error_if_friendly_id_is_blank
|
159
|
-
assert_raises(FriendlyId::SlugGenerationError) do
|
160
|
-
Post.create(:name => nil)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_should_raise_error_if_normalized_friendly_id_becomes_blank
|
165
|
-
assert_raises(FriendlyId::SlugGenerationError) do
|
166
|
-
post = Post.create!(:name => "-.-")
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_should_raise_error_if_slug_text_is_reserved
|
171
|
-
assert_raises(FriendlyId::SlugGenerationError) do
|
172
|
-
Post.create(:name => "new")
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_should_allow_eager_loading_of_slugs
|
177
|
-
assert_nothing_raised do
|
178
|
-
Post.find(slugs(:one).name, :include => :slugs)
|
179
|
-
end
|
180
|
-
assert_nothing_raised do
|
181
|
-
Post.find([slugs(:one).name, slugs(:two_new).name], :include => :slugs)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
end
|