friendly_id 5.0.3 → 5.0.4
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Changelog.md +15 -2
- data/MIT-LICENSE +1 -1
- data/README.md +3 -8
- data/friendly_id.gemspec +1 -1
- data/gemfiles/Gemfile.rails-4.1.rb +3 -3
- data/gemfiles/Gemfile.rails-stable.rb +1 -1
- data/lib/friendly_id/base.rb +1 -1
- data/lib/friendly_id/finder_methods.rb +1 -1
- data/lib/friendly_id/scoped.rb +2 -5
- data/lib/friendly_id/slugged.rb +14 -6
- data/lib/friendly_id/version.rb +1 -1
- data/test/helper.rb +2 -0
- data/test/schema.rb +4 -4
- data/test/slugged_test.rb +44 -15
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6650a7d112a806cb566708865ade666184dab77a
|
4
|
+
data.tar.gz: 2cde3e354e65e588d566a02f7e61d2b7e5e77657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38805122e7a3cef575c89dab8945589815c80d871ec01f6f2932fb7542a9240b00cdb3506d8cc1edbe5f42aa65d96c66cf5c3909dd9f4eefd5dfa03745f846c9
|
7
|
+
data.tar.gz: fc87f81b4c941571d34c961efa2fa6c81fbb02c29befa9a7b615ff7a3c392884f8dea699be2774c231449aeb2c982a38aea47bc7504b70e5f34b2847d0a491ae
|
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -3,14 +3,27 @@
|
|
3
3
|
We would like to think our many {file:Contributors contributors} for
|
4
4
|
suggestions, ideas and improvements to FriendlyId.
|
5
5
|
|
6
|
+
## 5.0.4 (2014-05-29)
|
7
|
+
|
8
|
+
* Bug fix for call to removed `primary` method on Edge Rails. ([#557](https://github.com/norman/friendly_id/pull/557)).
|
9
|
+
* Bug for for unwanted slug regeneration when the slug source was not changed, but not the actual generated slug ([#563](https://github.com/norman/friendly_id/pull/562)).
|
10
|
+
* Big fix to look for UUIDs only at the end of slugs ([#548](https://github.com/norman/friendly_id/pull/548)).
|
11
|
+
* Various documentation and test setup improvements.
|
12
|
+
|
13
|
+
|
14
|
+
## 5.0.3 (2013-02-14)
|
15
|
+
|
16
|
+
* Bug fix for calls to #dup with unslugged models ([#518](https://github.com/norman/friendly_id/pull/518)).
|
17
|
+
* Bug fixes for STI ([#516](https://github.com/norman/friendly_id/pull/516)).
|
18
|
+
* Bug fix for slug regeneration (both scoped and unscoped) ([#513](https://github.com/norman/friendly_id/pull/513)).
|
19
|
+
* Bug fix for finds with models that use the :history module ([#509](https://github.com/norman/friendly_id/pull/509)).
|
20
|
+
|
6
21
|
## 5.0.2 (2013-12-10)
|
7
22
|
|
8
23
|
* Query performance improvements ([#497](https://github.com/norman/friendly_id/pull/497)).
|
9
24
|
* Documentation improvements (thanks [John Bachir](https://github.com/jjb)).
|
10
25
|
* Minor refactoring of internals (thanks [Gagan Ahwad](https://github.com/gaganawhad)).
|
11
26
|
* Set slug to `nil` on call to `dup` to ensure slug is generated ([#483](https://github.com/norman/friendly_id/pull/483)).
|
12
|
-
* Bug fixes for STI ([#516](https://github.com/norman/friendly_id/pull/516)).
|
13
|
-
* Bug fix for finds with models that use the :history module ([#509](https://github.com/norman/friendly_id/pull/509)).
|
14
27
|
|
15
28
|
## 5.0.1 (2013-10-27)
|
16
29
|
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2008-
|
1
|
+
Copyright (c) 2008-2014 Norman Clarke, Adrian Mugnolo and Emilio Tagua.
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -145,6 +145,7 @@ Docs for older versions are also available:
|
|
145
145
|
|
146
146
|
* [4.0](http://norman.github.io/friendly_id/4.0/)
|
147
147
|
* [3.3](http://norman.github.io/friendly_id/3.3/)
|
148
|
+
* [2.3](http://norman.github.io/friendly_id/2.3/)
|
148
149
|
|
149
150
|
The best place to start is with the
|
150
151
|
[Guide](http://norman.github.io/friendly_id/file.Guide.html),
|
@@ -165,13 +166,7 @@ gem 'friendly_id', '~> 5.0.0' # Note: You MUST use 5.0.0 or greater for Rails 4.
|
|
165
166
|
```
|
166
167
|
```shell
|
167
168
|
rails generate friendly_id
|
168
|
-
rails generate scaffold user name:string slug:string
|
169
|
-
```
|
170
|
-
```ruby
|
171
|
-
# edit db/migrate/*_create_users.rb
|
172
|
-
add_index :users, :slug, unique: true
|
173
|
-
```
|
174
|
-
```shell
|
169
|
+
rails generate scaffold user name:string slug:string:uniq
|
175
170
|
rake db:migrate
|
176
171
|
```
|
177
172
|
```ruby
|
@@ -233,7 +228,7 @@ volunteers](https://github.com/norman/friendly_id/contributors).
|
|
233
228
|
|
234
229
|
## License
|
235
230
|
|
236
|
-
Copyright (c) 2008-
|
231
|
+
Copyright (c) 2008-2014 Norman Clarke and contributors, released under the MIT
|
237
232
|
license.
|
238
233
|
|
239
234
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
data/friendly_id.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_dependency 'activerecord', '>= 4.0.0'
|
20
20
|
|
21
21
|
s.add_development_dependency 'coveralls'
|
22
|
-
s.add_development_dependency 'railties', '~> 4.0
|
22
|
+
s.add_development_dependency 'railties', '~> 4.0'
|
23
23
|
s.add_development_dependency 'minitest', '>= 4.4.0'
|
24
24
|
s.add_development_dependency 'mocha', '~> 0.13.3'
|
25
25
|
s.add_development_dependency 'yard'
|
@@ -2,8 +2,8 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec path: '../'
|
4
4
|
|
5
|
-
gem 'activerecord', '~> 4.1.0
|
6
|
-
gem 'railties', '~> 4.1.0
|
5
|
+
gem 'activerecord', '~> 4.1.0'
|
6
|
+
gem 'railties', '~> 4.1.0'
|
7
7
|
|
8
8
|
# Database Configuration
|
9
9
|
group :development, :test do
|
@@ -26,4 +26,4 @@ group :development, :test do
|
|
26
26
|
gem 'rubinius-developer_tools'
|
27
27
|
gem 'json'
|
28
28
|
end
|
29
|
-
end
|
29
|
+
end
|
data/lib/friendly_id/base.rb
CHANGED
data/lib/friendly_id/scoped.rb
CHANGED
@@ -126,11 +126,8 @@ an example of one way to set this up:
|
|
126
126
|
friendly_id_config.scope_columns.each do |column|
|
127
127
|
relation = relation.where(column => send(column))
|
128
128
|
end
|
129
|
-
|
130
|
-
|
131
|
-
relation = relation.where.not(primary_key_name => send(primary_key_name))
|
132
|
-
end
|
133
|
-
relation
|
129
|
+
primary_key_name = self.class.primary_key
|
130
|
+
relation.where.not(primary_key_name => send(primary_key_name))
|
134
131
|
end
|
135
132
|
private :scope_for_slug_generator
|
136
133
|
|
data/lib/friendly_id/slugged.rb
CHANGED
@@ -186,6 +186,18 @@ control exactly when new friendly ids are set:
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
+
If you want to extend the default behavior but, adding your own conditions,
|
190
|
+
don't forget to invoke `super` from your implementation:
|
191
|
+
|
192
|
+
class Category < ActiveRecord::Base
|
193
|
+
extend FriendlyId
|
194
|
+
friendly_id :name, :use => :slugged
|
195
|
+
|
196
|
+
def should_generate_new_friendly_id?
|
197
|
+
name_changed? || super
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
189
201
|
#### Locale-specific Transliterations
|
190
202
|
|
191
203
|
Active Support's `parameterize` uses
|
@@ -300,12 +312,8 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
300
312
|
def scope_for_slug_generator
|
301
313
|
scope = self.class.base_class.unscoped
|
302
314
|
scope = scope.friendly unless scope.respond_to?(:exists_by_friendly_id?)
|
303
|
-
|
304
|
-
|
305
|
-
primary_key_name = self.class.primary_key
|
306
|
-
scope = scope.where.not(primary_key_name => send(primary_key_name))
|
307
|
-
end
|
308
|
-
scope
|
315
|
+
primary_key_name = self.class.primary_key
|
316
|
+
scope.where.not(primary_key_name => send(primary_key_name))
|
309
317
|
end
|
310
318
|
private :scope_for_slug_generator
|
311
319
|
|
data/lib/friendly_id/version.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/schema.rb
CHANGED
@@ -23,10 +23,10 @@ module FriendlyId
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
create_table table_name, primary_key: :
|
26
|
+
tables_with_uuid_primary_key.each do |table_name|
|
27
|
+
create_table table_name, primary_key: :uuid_key, id: false do |t|
|
28
28
|
t.string :name
|
29
|
-
t.string :
|
29
|
+
t.string :uuid_key, null: false
|
30
30
|
t.string :slug
|
31
31
|
end
|
32
32
|
add_index table_name, :slug, unique: true
|
@@ -73,7 +73,7 @@ module FriendlyId
|
|
73
73
|
%w[journalists articles novelists novels manuals]
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
76
|
+
def tables_with_uuid_primary_key
|
77
77
|
["menu_items"]
|
78
78
|
end
|
79
79
|
|
data/test/slugged_test.rb
CHANGED
@@ -77,6 +77,21 @@ class SluggedTest < MiniTest::Unit::TestCase
|
|
77
77
|
assert_equal old_id, record.friendly_id
|
78
78
|
end
|
79
79
|
end
|
80
|
+
|
81
|
+
test "should not update matching slug" do
|
82
|
+
with_instance_of(model_class) do |record|
|
83
|
+
class << record
|
84
|
+
def should_generate_new_friendly_id?
|
85
|
+
name_changed?
|
86
|
+
end
|
87
|
+
end
|
88
|
+
old_id = record.friendly_id
|
89
|
+
record.name += " "
|
90
|
+
record.save!
|
91
|
+
assert_equal old_id, record.friendly_id
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
80
95
|
end
|
81
96
|
|
82
97
|
class SlugGeneratorTest < MiniTest::Unit::TestCase
|
@@ -119,10 +134,10 @@ class SlugGeneratorTest < MiniTest::Unit::TestCase
|
|
119
134
|
|
120
135
|
test "should correctly sequence slugs that end with numbers" do
|
121
136
|
transaction do
|
122
|
-
record1 = model_class.create! :name => "
|
123
|
-
assert_equal "
|
124
|
-
record2 = model_class.create! :name => "
|
125
|
-
assert_match(/\
|
137
|
+
record1 = model_class.create! :name => "Peugeot 206"
|
138
|
+
assert_equal "peugeot-206", record1.slug
|
139
|
+
record2 = model_class.create! :name => "Peugeot 206"
|
140
|
+
assert_match(/\Apeugeot-206-([a-z0-9]+\-){4}[a-z0-9]+\z/, record2.slug)
|
126
141
|
end
|
127
142
|
end
|
128
143
|
|
@@ -209,10 +224,10 @@ class SlugSeparatorTest < MiniTest::Unit::TestCase
|
|
209
224
|
end
|
210
225
|
end
|
211
226
|
transaction do
|
212
|
-
record1 = model_class.create! :name => "
|
213
|
-
assert_equal "
|
214
|
-
record2 = model_class.create! :name => "
|
215
|
-
assert_match(/\
|
227
|
+
record1 = model_class.create! :name => "Peugeot 206"
|
228
|
+
assert_equal "peugeot-206", record1.slug
|
229
|
+
record2 = model_class.create! :name => "Peugeot 206"
|
230
|
+
assert_match(/\Apeugeot-206-([a-z0-9]+\-){4}[a-z0-9]+\z/, record2.slug)
|
216
231
|
end
|
217
232
|
end
|
218
233
|
end
|
@@ -241,7 +256,7 @@ class DefaultScopeTest < MiniTest::Unit::TestCase
|
|
241
256
|
end
|
242
257
|
end
|
243
258
|
|
244
|
-
class
|
259
|
+
class UuidAsPrimaryKeyFindTest < MiniTest::Unit::TestCase
|
245
260
|
include FriendlyId::Test
|
246
261
|
|
247
262
|
class MenuItem < ActiveRecord::Base
|
@@ -250,12 +265,17 @@ class StringAsPrimaryKeyFindTest < MiniTest::Unit::TestCase
|
|
250
265
|
before_create :init_primary_key
|
251
266
|
|
252
267
|
def self.primary_key
|
253
|
-
"
|
268
|
+
"uuid_key"
|
269
|
+
end
|
270
|
+
|
271
|
+
# Overwrite the method added by FriendlyId
|
272
|
+
def self.primary_key_type
|
273
|
+
:uuid
|
254
274
|
end
|
255
275
|
|
256
276
|
private
|
257
277
|
def init_primary_key
|
258
|
-
self.
|
278
|
+
self.uuid_key = SecureRandom.uuid
|
259
279
|
end
|
260
280
|
end
|
261
281
|
|
@@ -263,16 +283,25 @@ class StringAsPrimaryKeyFindTest < MiniTest::Unit::TestCase
|
|
263
283
|
MenuItem
|
264
284
|
end
|
265
285
|
|
266
|
-
test "should have a
|
267
|
-
assert_equal model_class.primary_key, "
|
268
|
-
assert_equal model_class.columns.find
|
286
|
+
test "should have a uuid_key as a primary key" do
|
287
|
+
assert_equal model_class.primary_key, "uuid_key"
|
288
|
+
assert_equal model_class.columns.find { |c| c.name == model_class.primary_key}.name, "uuid_key"
|
289
|
+
assert_equal model_class.primary_key_type, :uuid
|
269
290
|
end
|
270
291
|
|
271
|
-
test "should be findable by the
|
292
|
+
test "should be findable by the UUID primary key" do
|
272
293
|
with_instance_of(model_class) do |record|
|
273
294
|
assert model_class.friendly.find record.id
|
274
295
|
end
|
275
296
|
end
|
297
|
+
|
298
|
+
test "should handle a string that simply contains a UUID correctly" do
|
299
|
+
with_instance_of(model_class) do |record|
|
300
|
+
assert_raises(ActiveRecord::RecordNotFound) do
|
301
|
+
model_class.friendly.find "test-#{SecureRandom.uuid}"
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
276
305
|
end
|
277
306
|
|
278
307
|
class UnderscoreAsSequenceSeparatorRegressionTest < 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: 5.0.
|
4
|
+
version: 5.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 4.0
|
48
|
+
version: '4.0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 4.0
|
55
|
+
version: '4.0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: minitest
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
219
|
version: '0'
|
220
220
|
requirements: []
|
221
221
|
rubyforge_project: friendly_id
|
222
|
-
rubygems_version: 2.2.
|
222
|
+
rubygems_version: 2.2.2
|
223
223
|
signing_key:
|
224
224
|
specification_version: 4
|
225
225
|
summary: A comprehensive slugging and pretty-URL plugin.
|