friendly_id 4.0.6 → 4.0.7
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/Changelog.md +8 -0
- data/lib/friendly_id.rb +1 -1
- data/lib/friendly_id/base.rb +1 -1
- data/lib/friendly_id/slug_generator.rb +1 -2
- data/lib/friendly_id/slugged.rb +3 -2
- data/test/shared.rb +4 -0
- data/test/slugged_test.rb +33 -0
- metadata +2 -2
data/Changelog.md
CHANGED
@@ -6,6 +6,14 @@ suggestions, ideas and improvements to FriendlyId.
|
|
6
6
|
* Table of Contents
|
7
7
|
{:toc}
|
8
8
|
|
9
|
+
## 4.0.7 (2012-06-06)
|
10
|
+
|
11
|
+
* to_param just calls super when no friendly_id is present, to keep the model's
|
12
|
+
default behavior. (Andrew White)
|
13
|
+
|
14
|
+
* FriendlyId can now properly sequence slugs that end in numbers even when a
|
15
|
+
single dash is used as the separator (Tomás Arribas).
|
16
|
+
|
9
17
|
## 4.0.6 (2012-05-21)
|
10
18
|
|
11
19
|
* Fix nil return value from to_param when save fails because of validation errors (Tomás Arribas)
|
data/lib/friendly_id.rb
CHANGED
data/lib/friendly_id/base.rb
CHANGED
@@ -268,7 +268,7 @@ often better and easier to use {FriendlyId::Slugged slugs}.
|
|
268
268
|
if diff = changes[friendly_id_config.query_field]
|
269
269
|
diff.first || diff.second
|
270
270
|
else
|
271
|
-
friendly_id.
|
271
|
+
friendly_id.presence || super
|
272
272
|
end
|
273
273
|
end
|
274
274
|
end
|
@@ -31,8 +31,7 @@ module FriendlyId
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def extract_sequence_from_slug(slug)
|
34
|
-
#
|
35
|
-
slug.gsub(/^#{Regexp.quote(normalized)}(#{Regexp.quote(separator)})?/, '').to_i
|
34
|
+
slug.split("#{normalized}#{separator}").last.to_i
|
36
35
|
end
|
37
36
|
|
38
37
|
def column
|
data/lib/friendly_id/slugged.rb
CHANGED
@@ -261,9 +261,10 @@ issue}[https://github.com/norman/friendly_id/issues/180] for discussion.
|
|
261
261
|
return true if new_record?
|
262
262
|
slug_base = normalize_friendly_id(base)
|
263
263
|
separator = Regexp.escape friendly_id_config.sequence_separator
|
264
|
-
# If the slug base (without sequence) is different from either the current
|
264
|
+
# If the slug base (with and without sequence) is different from either the current
|
265
265
|
# friendly id or the slug value, then we'll generate a new friendly_id.
|
266
|
-
|
266
|
+
compare = (current_friendly_id || slug_value)
|
267
|
+
slug_base != compare && slug_base != compare.try(:sub, /#{separator}[\d]*\z/, '')
|
267
268
|
end
|
268
269
|
|
269
270
|
# Sets the slug.
|
data/test/shared.rb
CHANGED
data/test/slugged_test.rb
CHANGED
@@ -159,6 +159,39 @@ class SlugSeparatorTest < MiniTest::Unit::TestCase
|
|
159
159
|
assert record2.should_generate_new_friendly_id?
|
160
160
|
end
|
161
161
|
end
|
162
|
+
|
163
|
+
test "should correctly sequence slugs that uses single dashes as sequence separator" do
|
164
|
+
model_class = Class.new(ActiveRecord::Base) do
|
165
|
+
self.table_name = "journalists"
|
166
|
+
extend FriendlyId
|
167
|
+
friendly_id :name, :use => :slugged, :sequence_separator => '-'
|
168
|
+
def self.name
|
169
|
+
"Journalist"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
transaction do
|
173
|
+
record1 = model_class.create! :name => "Peugeuot 206"
|
174
|
+
assert_equal "peugeuot-206", record1.slug
|
175
|
+
record2 = model_class.create! :name => "Peugeuot 206"
|
176
|
+
assert_equal "peugeuot-206-2", record2.slug
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
test "should detect when a sequenced slug has changed when name ends in number and using single dash" do
|
181
|
+
model_class = Class.new(ActiveRecord::Base) do
|
182
|
+
self.table_name = "journalists"
|
183
|
+
extend FriendlyId
|
184
|
+
friendly_id :name, :use => :slugged, :sequence_separator => '-'
|
185
|
+
end
|
186
|
+
transaction do
|
187
|
+
record1 = model_class.create! :name => "Peugeuot 206"
|
188
|
+
assert !record1.should_generate_new_friendly_id?
|
189
|
+
record1.save!
|
190
|
+
assert !record1.should_generate_new_friendly_id?
|
191
|
+
record1.name = "Peugeot 307"
|
192
|
+
assert record1.should_generate_new_friendly_id?
|
193
|
+
end
|
194
|
+
end
|
162
195
|
end
|
163
196
|
|
164
197
|
class DefaultScopeTest < MiniTest::Unit::TestCase
|
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.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|