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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e2080c5099215c8dafa04072948b2ac30907bb8
4
- data.tar.gz: bee56373516dd5ed394d7de3bc554a08560d5433
3
+ metadata.gz: 8ecc233dd377f5400a788a6a6fb7d37e2f4b200c
4
+ data.tar.gz: 9c848d7c0f238d70577cb0737b1f6411e779a6d5
5
5
  SHA512:
6
- metadata.gz: 015d359758f15798d9f51ff5cd22462510a48e523fa4b3c0c4a7a8aefd8b370039dce2bc78484a54d05be82e0b7b57284d4763d943eaec35c1418fb5b23cc2ba
7
- data.tar.gz: 66ebbb5b6f6345c6beb0d5c4668ba61d5f9e26b2cff24ab8c8591ed36489559584f24fb00ef41b52aefc568ebc5fd121a200d89db8a04948a23a06aa100cb758
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
@@ -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.5'
24
- s.add_development_dependency 'mocha', '~> 1.1.0'
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'
@@ -46,6 +46,7 @@ message to a different field. For example:
46
46
  # {FriendlyId::Configuration FriendlyId::Configuration}.
47
47
  module Configuration
48
48
  attr_accessor :reserved_words
49
+ attr_accessor :treat_reserved_as_conflict
49
50
  end
50
51
  end
51
52
  end
@@ -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
 
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module FriendlyId
2
- VERSION = '5.2.2'.freeze
2
+ VERSION = '5.2.3'.freeze
3
3
  end
@@ -14,8 +14,8 @@ class ObjectUtilsTest < TestCaseClass
14
14
  end
15
15
 
16
16
  test "numeric strings are neither friendly nor unfriendly" do
17
- assert_equal nil, "1".friendly_id?
18
- assert_equal nil, "1".unfriendly_id?
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
@@ -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
@@ -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[:name] = "FAIL"}
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
- assert_equal nil, model_class.new.to_param
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.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-14 00:00:00.000000000 Z
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.5
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.5
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.0
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.0
83
+ version: '1.1'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: yard
86
86
  requirement: !ruby/object:Gem::Requirement