friendly_id 5.2.2 → 5.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/friendly_id.gemspec +2 -2
- data/lib/friendly_id/reserved.rb +1 -0
- data/lib/friendly_id/scoped.rb +1 -1
- data/lib/friendly_id/slug_generator.rb +6 -1
- data/lib/friendly_id/slugged.rb +1 -1
- data/lib/friendly_id/version.rb +1 -1
- data/test/object_utils_test.rb +3 -3
- data/test/reserved_test.rb +10 -0
- data/test/shared.rb +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ecc233dd377f5400a788a6a6fb7d37e2f4b200c
|
4
|
+
data.tar.gz: 9c848d7c0f238d70577cb0737b1f6411e779a6d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c0a2db2212245e2dcadd50a6f62e3970a10ca72d7230e92cebf31a03da6772c23d2203303e08ff51ed9c9985f234310e01db91f0baa79c663c9756b84181b7a
|
7
|
+
data.tar.gz: cc539ec2396d5736499c3852d0bd967c10d1d6d0ec3afd63b137634e9ac7f6365d7b073895c5297390a42ad74a9cb363064c81c317ad899f3e44f6f15a312f19
|
data/README.md
CHANGED
@@ -177,7 +177,6 @@ rails generate friendly_id
|
|
177
177
|
```
|
178
178
|
>Temp solution for Rails 5.1+ : Before running the migration, go into the generated migration file and specify the Rails version:
|
179
179
|
`class CreateFriendlyIdSlugs < ActiveRecord::Migration[5.1]`
|
180
|
-
```
|
181
180
|
```shell
|
182
181
|
rails generate scaffold user name:string slug:string:uniq
|
183
182
|
rake db:migrate
|
data/friendly_id.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.add_development_dependency 'coveralls'
|
22
22
|
s.add_development_dependency 'railties', '~> 4.0'
|
23
|
-
s.add_development_dependency 'minitest', '~> 5.3
|
24
|
-
s.add_development_dependency 'mocha', '~> 1.1
|
23
|
+
s.add_development_dependency 'minitest', '~> 5.3'
|
24
|
+
s.add_development_dependency 'mocha', '~> 1.1'
|
25
25
|
s.add_development_dependency 'yard'
|
26
26
|
s.add_development_dependency 'i18n'
|
27
27
|
s.add_development_dependency 'ffaker'
|
data/lib/friendly_id/reserved.rb
CHANGED
data/lib/friendly_id/scoped.rb
CHANGED
@@ -132,7 +132,7 @@ an example of one way to set this up:
|
|
132
132
|
private :scope_for_slug_generator
|
133
133
|
|
134
134
|
def slug_generator
|
135
|
-
friendly_id_config.slug_generator_class.new(scope_for_slug_generator)
|
135
|
+
friendly_id_config.slug_generator_class.new(scope_for_slug_generator, friendly_id_config)
|
136
136
|
end
|
137
137
|
private :slug_generator
|
138
138
|
|
@@ -3,11 +3,16 @@ module FriendlyId
|
|
3
3
|
# availability.
|
4
4
|
class SlugGenerator
|
5
5
|
|
6
|
-
def initialize(scope)
|
6
|
+
def initialize(scope, config)
|
7
7
|
@scope = scope
|
8
|
+
@config = config
|
8
9
|
end
|
9
10
|
|
10
11
|
def available?(slug)
|
12
|
+
if @config.uses?(::FriendlyId::Reserved) && @config.reserved_words.present? && @config.treat_reserved_as_conflict
|
13
|
+
return false if @config.reserved_words.include?(slug)
|
14
|
+
end
|
15
|
+
|
11
16
|
!@scope.exists_by_friendly_id?(slug)
|
12
17
|
end
|
13
18
|
|
data/lib/friendly_id/slugged.rb
CHANGED
@@ -370,7 +370,7 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
370
370
|
private :scope_for_slug_generator
|
371
371
|
|
372
372
|
def slug_generator
|
373
|
-
friendly_id_config.slug_generator_class.new(scope_for_slug_generator)
|
373
|
+
friendly_id_config.slug_generator_class.new(scope_for_slug_generator, friendly_id_config)
|
374
374
|
end
|
375
375
|
private :slug_generator
|
376
376
|
|
data/lib/friendly_id/version.rb
CHANGED
data/test/object_utils_test.rb
CHANGED
@@ -14,8 +14,8 @@ class ObjectUtilsTest < TestCaseClass
|
|
14
14
|
end
|
15
15
|
|
16
16
|
test "numeric strings are neither friendly nor unfriendly" do
|
17
|
-
|
18
|
-
|
17
|
+
assert_nil "1".friendly_id?
|
18
|
+
assert_nil "1".unfriendly_id?
|
19
19
|
end
|
20
20
|
|
21
21
|
test "ActiveRecord::Base instances should be unfriendly_ids" do
|
@@ -24,4 +24,4 @@ class ObjectUtilsTest < TestCaseClass
|
|
24
24
|
end
|
25
25
|
assert model_class.new.unfriendly_id?
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
data/test/reserved_test.rb
CHANGED
@@ -62,4 +62,14 @@ class ReservedTest < TestCaseClass
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
test "should optionally treat reserved words as conflict" do
|
66
|
+
klass = Class.new(model_class) do
|
67
|
+
friendly_id :slug_candidates, :use => [:slugged, :reserved], :reserved_words => %w(new edit), :treat_reserved_as_conflict => true
|
68
|
+
end
|
69
|
+
|
70
|
+
with_instance_of(klass, name: 'new') do |record|
|
71
|
+
assert_match(/new-([0-9a-z]+\-){4}[0-9a-z]+\z/, record.slug)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
65
75
|
end
|
data/test/shared.rb
CHANGED
@@ -64,7 +64,7 @@ module FriendlyId
|
|
64
64
|
with_instance_of my_model_class do |record|
|
65
65
|
record.update_attributes my_model_class.friendly_id_config.slug_column => nil
|
66
66
|
record = my_model_class.friendly.find(record.id)
|
67
|
-
record.class.validate Proc.new {errors
|
67
|
+
record.class.validate Proc.new {errors.add(:name, "FAIL")}
|
68
68
|
record.save
|
69
69
|
assert_equal record.to_param, record.friendly_id
|
70
70
|
end
|
@@ -174,7 +174,7 @@ module FriendlyId
|
|
174
174
|
end
|
175
175
|
|
176
176
|
test "should return nil for to_param with a new record" do
|
177
|
-
|
177
|
+
assert_nil model_class.new.to_param
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|
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.2.
|
4
|
+
version: 5.2.3
|
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: 2017-09-
|
12
|
+
date: 2017-09-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -59,28 +59,28 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 5.3
|
62
|
+
version: '5.3'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 5.3
|
69
|
+
version: '5.3'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: mocha
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 1.1
|
76
|
+
version: '1.1'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: 1.1
|
83
|
+
version: '1.1'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: yard
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|