friendly_id 4.0.5 → 4.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -2
- data/Changelog.md +6 -0
- data/Gemfile +15 -0
- data/lib/friendly_id.rb +1 -1
- data/lib/friendly_id/base.rb +1 -1
- data/lib/friendly_id/reserved.rb +1 -1
- data/lib/friendly_id/simple_i18n.rb +1 -1
- data/test/compatibility/ancestry/Gemfile +8 -0
- data/test/compatibility/threading/Gemfile +8 -0
- data/test/reserved_test.rb +17 -3
- data/test/shared.rb +12 -0
- data/test/{i18n_test.rb → simple_i18n_test.rb} +13 -2
- metadata +74 -24
data/.gitignore
CHANGED
data/Changelog.md
CHANGED
@@ -6,6 +6,12 @@ suggestions, ideas and improvements to FriendlyId.
|
|
6
6
|
* Table of Contents
|
7
7
|
{:toc}
|
8
8
|
|
9
|
+
## 4.0.6 (2012-05-21)
|
10
|
+
|
11
|
+
* Fix nil return value from to_param when save fails because of validation errors (Tomás Arribas)
|
12
|
+
* Fix incorrect usage of i18n API (Vinicius Ferriani)
|
13
|
+
* Improve error handling in reserved module (Adrián Mugnolo and Github user "nolamesa")
|
14
|
+
|
9
15
|
## 4.0.5 (2012-04-28)
|
10
16
|
|
11
17
|
* Favor `includes` over `joins` in globalize to avoid read-only results (Jakub Wojtysiak)
|
data/Gemfile
ADDED
data/lib/friendly_id.rb
CHANGED
data/lib/friendly_id/base.rb
CHANGED
@@ -266,7 +266,7 @@ often better and easier to use {FriendlyId::Slugged slugs}.
|
|
266
266
|
# Either the friendly_id, or the numeric id cast to a string.
|
267
267
|
def to_param
|
268
268
|
if diff = changes[friendly_id_config.query_field]
|
269
|
-
diff.first
|
269
|
+
diff.first || diff.second
|
270
270
|
else
|
271
271
|
friendly_id.present? ? friendly_id : id.to_s
|
272
272
|
end
|
data/lib/friendly_id/reserved.rb
CHANGED
@@ -30,7 +30,7 @@ For example:
|
|
30
30
|
after_validation :move_friendly_id_error_to_name
|
31
31
|
|
32
32
|
def move_friendly_id_error_to_name
|
33
|
-
errors.
|
33
|
+
errors.add :name, *errors.delete(:friendly_id) if errors[:friendly_id].present?
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
data/test/reserved_test.rb
CHANGED
@@ -7,20 +7,34 @@ class ReservedTest < MiniTest::Unit::TestCase
|
|
7
7
|
class Journalist < ActiveRecord::Base
|
8
8
|
extend FriendlyId
|
9
9
|
friendly_id :name
|
10
|
-
end
|
11
10
|
|
11
|
+
after_validation :move_friendly_id_error_to_name
|
12
|
+
|
13
|
+
def move_friendly_id_error_to_name
|
14
|
+
errors.add :name, *errors.delete(:friendly_id) if errors[:friendly_id].present?
|
15
|
+
end
|
16
|
+
end
|
12
17
|
|
13
18
|
def model_class
|
14
19
|
Journalist
|
15
20
|
end
|
16
21
|
|
17
22
|
test "should reserve 'new' and 'edit' by default" do
|
18
|
-
|
23
|
+
%w(new edit).each do |word|
|
19
24
|
transaction do
|
20
25
|
assert_raises(ActiveRecord::RecordInvalid) {model_class.create! :name => word}
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
24
|
-
end
|
25
29
|
|
30
|
+
test "should move friendly_id error to name" do
|
31
|
+
with_instance_of(model_class) do |record|
|
32
|
+
record.errors.add :name, "xxx"
|
33
|
+
record.errors.add :friendly_id, "yyy"
|
34
|
+
record.move_friendly_id_error_to_name
|
35
|
+
assert record.errors[:name].present? && record.errors[:friendly_id].blank?
|
36
|
+
assert_equal 2, record.errors.count
|
37
|
+
end
|
38
|
+
end
|
26
39
|
|
40
|
+
end
|
data/test/shared.rb
CHANGED
@@ -51,6 +51,18 @@ module FriendlyId
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
test "when validations block save, to_param should return friendly_id rather than nil" do
|
55
|
+
my_model_class = Class.new(model_class)
|
56
|
+
self.class.const_set("Foo", my_model_class)
|
57
|
+
with_instance_of my_model_class do |record|
|
58
|
+
record.update_attribute(my_model_class.friendly_id_config.slug_column, nil)
|
59
|
+
record = my_model_class.find(record.id)
|
60
|
+
record.class.validate Proc.new {errors[:name] = "FAIL"}
|
61
|
+
record.save
|
62
|
+
assert_equal record.to_param, record.friendly_id
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
54
66
|
end
|
55
67
|
|
56
68
|
module Core
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
|
-
class
|
3
|
+
class SimpleI18nTest < MiniTest::Unit::TestCase
|
4
4
|
include FriendlyId::Test
|
5
5
|
|
6
6
|
class Journalist < ActiveRecord::Base
|
@@ -8,7 +8,7 @@ class I18nTest < MiniTest::Unit::TestCase
|
|
8
8
|
friendly_id :name, :use => :simple_i18n
|
9
9
|
end
|
10
10
|
|
11
|
-
test "friendly_id should return
|
11
|
+
test "friendly_id should return the current locale's slug" do
|
12
12
|
journalist = Journalist.new(:name => "John Doe")
|
13
13
|
journalist.slug_es = "juan-fulano"
|
14
14
|
journalist.valid?
|
@@ -58,6 +58,17 @@ class I18nTest < MiniTest::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
test "set friendly_id should fall back default locale when none is given" do
|
62
|
+
transaction do
|
63
|
+
journalist = I18n.with_locale(:es) do
|
64
|
+
Journalist.create!(:name => "Juan Fulano")
|
65
|
+
end
|
66
|
+
journalist.set_friendly_id("John Doe")
|
67
|
+
journalist.save!
|
68
|
+
assert_equal "john-doe", journalist.slug_en
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
61
72
|
test "should sequence localized slugs" do
|
62
73
|
transaction do
|
63
74
|
journalist = Journalist.create!(:name => "John Smith")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendly_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 3.2.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: activerecord
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 3.2.0
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.2.0
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: minitest
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: mocha
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: maruku
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: yard
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: i18n
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,10 +117,15 @@ dependencies:
|
|
87
117
|
version: '0'
|
88
118
|
type: :development
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
91
126
|
- !ruby/object:Gem::Dependency
|
92
127
|
name: ffaker
|
93
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
94
129
|
none: false
|
95
130
|
requirements:
|
96
131
|
- - ! '>='
|
@@ -98,10 +133,15 @@ dependencies:
|
|
98
133
|
version: '0'
|
99
134
|
type: :development
|
100
135
|
prerelease: false
|
101
|
-
version_requirements:
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
102
142
|
- !ruby/object:Gem::Dependency
|
103
143
|
name: simplecov
|
104
|
-
requirement:
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
105
145
|
none: false
|
106
146
|
requirements:
|
107
147
|
- - ! '>='
|
@@ -109,10 +149,15 @@ dependencies:
|
|
109
149
|
version: '0'
|
110
150
|
type: :development
|
111
151
|
prerelease: false
|
112
|
-
version_requirements:
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
113
158
|
- !ruby/object:Gem::Dependency
|
114
159
|
name: globalize3
|
115
|
-
requirement:
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
116
161
|
none: false
|
117
162
|
requirements:
|
118
163
|
- - ! '>='
|
@@ -120,7 +165,12 @@ dependencies:
|
|
120
165
|
version: '0'
|
121
166
|
type: :development
|
122
167
|
prerelease: false
|
123
|
-
version_requirements:
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
124
174
|
description: ! 'FriendlyId is the "Swiss Army bulldozer" of slugging and permalink
|
125
175
|
plugins for
|
126
176
|
|
@@ -179,12 +229,12 @@ files:
|
|
179
229
|
- test/globalize_test.rb
|
180
230
|
- test/helper.rb
|
181
231
|
- test/history_test.rb
|
182
|
-
- test/i18n_test.rb
|
183
232
|
- test/object_utils_test.rb
|
184
233
|
- test/reserved_test.rb
|
185
234
|
- test/schema.rb
|
186
235
|
- test/scoped_test.rb
|
187
236
|
- test/shared.rb
|
237
|
+
- test/simple_i18n_test.rb
|
188
238
|
- test/slugged_test.rb
|
189
239
|
- test/sti_test.rb
|
190
240
|
homepage: http://github.com/norman/friendly_id
|
@@ -216,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
266
|
version: '0'
|
217
267
|
requirements: []
|
218
268
|
rubyforge_project: friendly_id
|
219
|
-
rubygems_version: 1.8.
|
269
|
+
rubygems_version: 1.8.24
|
220
270
|
signing_key:
|
221
271
|
specification_version: 3
|
222
272
|
summary: A comprehensive slugging and pretty-URL plugin.
|