friendly_id 5.4.1 → 5.4.2
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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.github/workflows/test.yml +4 -15
- data/Changelog.md +5 -0
- data/lib/friendly_id/finder_methods.rb +39 -6
- data/lib/friendly_id/slugged.rb +1 -0
- data/lib/friendly_id/version.rb +1 -1
- data/test/finders_test.rb +0 -24
- data/test/slugged_test.rb +31 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21ddfb374efbecb41ddb5164a5f0fbb4df5838edfcb13a8e7d8d6caa1b378f34
|
4
|
+
data.tar.gz: 363955e55e33b9b15d59099f1b6ac00d88f32e0b3835f1dfd6fcf718aad7ac7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d966763a10e683b815681576ef71c720caeafee88c49f866f912cae1a2aae12a33fd00bfc93f2d0eb7204ae2b91c514613edf34996119519613452b0ce0cdfb1
|
7
|
+
data.tar.gz: f8e8522f7f4b1c8a32bc8fd58c719d8376beb3325f2adfbca0554f7ec63a2742d5ab5b7128bbf2fa3f106075f5f89af590843c36bf3924d975674bada3673ca9
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.github/workflows/test.yml
CHANGED
@@ -9,35 +9,24 @@ jobs:
|
|
9
9
|
test:
|
10
10
|
strategy:
|
11
11
|
matrix:
|
12
|
-
architecture: [ x64 ]
|
13
12
|
database: [ mysql, postgresql ]
|
14
13
|
gemfile: [ '6.0', '5.2' ]
|
15
|
-
ruby: [ '2.7
|
14
|
+
ruby: [ '2.7', '2.6', '2.5' ]
|
16
15
|
fail-fast: false
|
17
16
|
runs-on: ubuntu-latest
|
18
17
|
name: ${{ matrix.ruby }} ${{ matrix.database }} rails-${{ matrix.gemfile }}
|
19
18
|
steps:
|
20
|
-
- uses: actions/setup-ruby@v1.0.0
|
21
|
-
with:
|
22
|
-
architecture: ${{ matrix.architecture }}
|
23
|
-
ruby-version: ${{ matrix.ruby }}
|
24
|
-
version: ${{ matrix.ruby }}
|
25
19
|
- uses: actions/checkout@v2
|
26
20
|
- run: sudo apt-get update && sudo apt-get install libpq-dev postgresql-client libmysqlclient-dev mysql-client libsqlite3-dev -y
|
27
|
-
-
|
28
|
-
uses: actions/cache@v2
|
21
|
+
- uses: ruby/setup-ruby@v1
|
29
22
|
with:
|
30
|
-
|
31
|
-
|
32
|
-
- run: gem install bundler
|
33
|
-
- run: bundle install --path vendor/bundle
|
23
|
+
bundler-cache: true
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
34
25
|
- run: bundle exec rake db:create db:up
|
35
26
|
- run: bundle exec rake test
|
36
27
|
|
37
28
|
env:
|
38
|
-
BUNDLE_JOBS: 4
|
39
29
|
BUNDLE_GEMFILE: gemfiles/Gemfile.rails-${{ matrix.gemfile }}.rb
|
40
|
-
BUNDLE_PATH: vendor/bundle
|
41
30
|
CI: true
|
42
31
|
COVERALLS: true
|
43
32
|
DB: ${{ matrix.database }}
|
data/Changelog.md
CHANGED
@@ -5,6 +5,11 @@ suggestions, ideas and improvements to FriendlyId.
|
|
5
5
|
|
6
6
|
## Unreleased
|
7
7
|
|
8
|
+
## 5.4.2 (2021-01-07)
|
9
|
+
|
10
|
+
* Fix: Set slug before save if needed ([#948](https://github.com/norman/friendly_id/pull/948))
|
11
|
+
* Revert "Make `first_by_friendly_id` case insensitive using `downcase`" ([#951](https://github.com/norman/friendly_id/pull/951))
|
12
|
+
|
8
13
|
## 5.4.1 (2020-11-06)
|
9
14
|
|
10
15
|
* Fix unexpected `:slug` error on valid, unpersisted model ([#952](https://github.com/norman/friendly_id/pull/952))
|
@@ -20,8 +20,8 @@ module FriendlyId
|
|
20
20
|
return super if args.count != 1 || id.unfriendly_id?
|
21
21
|
first_by_friendly_id(id).tap {|result| return result unless result.nil?}
|
22
22
|
return super if potential_primary_key?(id)
|
23
|
-
|
24
|
-
|
23
|
+
|
24
|
+
raise_not_found_exception(id)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Returns true if a record with the given id exists.
|
@@ -39,7 +39,7 @@ module FriendlyId
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def exists_by_friendly_id?(id)
|
42
|
-
where(friendly_id_config.query_field => id).exists?
|
42
|
+
where(friendly_id_config.query_field => parse_friendly_id(id)).exists?
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
@@ -59,14 +59,47 @@ module FriendlyId
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def first_by_friendly_id(id)
|
62
|
-
find_by(friendly_id_config.query_field => id
|
62
|
+
find_by(friendly_id_config.query_field => parse_friendly_id(id))
|
63
|
+
end
|
64
|
+
|
65
|
+
# Parse the given value to make it suitable for use as a slug according to
|
66
|
+
# your application's rules.
|
67
|
+
#
|
68
|
+
# This method is not intended to be invoked directly; FriendlyId uses it
|
69
|
+
# internally to process a slug into string to use as a finder.
|
70
|
+
#
|
71
|
+
# However, if FriendlyId's default slug parsing doesn't suit your needs,
|
72
|
+
# you can override this method in your model class to control exactly how
|
73
|
+
# slugs are generated.
|
74
|
+
#
|
75
|
+
# ### Example
|
76
|
+
#
|
77
|
+
# class Person < ActiveRecord::Base
|
78
|
+
# extend FriendlyId
|
79
|
+
# friendly_id :name_and_location
|
80
|
+
#
|
81
|
+
# def name_and_location
|
82
|
+
# "#{name} from #{location}"
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# # Use default slug, but lower case
|
86
|
+
# # If `id` is "Jane-Doe" or "JANE-DOE", this finds data by "jane-doe"
|
87
|
+
# def parse_friendly_id(slug)
|
88
|
+
# super.downcase
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# @param [#to_s] value The slug to be parsed.
|
93
|
+
# @return The parsed slug, which is not modified by default.
|
94
|
+
def parse_friendly_id(value)
|
95
|
+
value
|
63
96
|
end
|
64
97
|
|
65
98
|
def raise_not_found_exception(id)
|
66
99
|
message = "can't find record with friendly id: #{id.inspect}"
|
67
|
-
if ActiveRecord.version < Gem::Version.create('5.0')
|
100
|
+
if ActiveRecord.version < Gem::Version.create('5.0')
|
68
101
|
raise ActiveRecord::RecordNotFound.new(message)
|
69
|
-
else
|
102
|
+
else
|
70
103
|
raise ActiveRecord::RecordNotFound.new(message, name, friendly_id_config.query_field, id)
|
71
104
|
end
|
72
105
|
end
|
data/lib/friendly_id/slugged.rb
CHANGED
@@ -248,6 +248,7 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
248
248
|
defaults[:sequence_separator] ||= '-'
|
249
249
|
end
|
250
250
|
model_class.before_validation :set_slug
|
251
|
+
model_class.before_save :set_slug
|
251
252
|
model_class.after_validation :unset_slug_if_invalid
|
252
253
|
end
|
253
254
|
|
data/lib/friendly_id/version.rb
CHANGED
data/test/finders_test.rb
CHANGED
@@ -26,28 +26,4 @@ class Finders < TestCaseClass
|
|
26
26
|
assert model_class.existing.find(record.friendly_id)
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
|
-
test 'should find capitalized records with finders as class methods' do
|
31
|
-
with_instance_of(model_class) do |record|
|
32
|
-
assert model_class.find(record.friendly_id.capitalize)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'should find capitalized records with finders on relations' do
|
37
|
-
with_instance_of(model_class) do |record|
|
38
|
-
assert model_class.existing.find(record.friendly_id.capitalize)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
test 'should find upcased records with finders as class methods' do
|
43
|
-
with_instance_of(model_class) do |record|
|
44
|
-
assert model_class.find(record.friendly_id.upcase)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
test 'should find upcased records with finders on relations' do
|
49
|
-
with_instance_of(model_class) do |record|
|
50
|
-
assert model_class.existing.find(record.friendly_id.upcase)
|
51
|
-
end
|
52
|
-
end
|
53
29
|
end
|
data/test/slugged_test.rb
CHANGED
@@ -479,6 +479,37 @@ class FailedValidationAfterUpdateRegressionTest < TestCaseClass
|
|
479
479
|
|
480
480
|
end
|
481
481
|
|
482
|
+
# https://github.com/norman/friendly_id/issues/947
|
483
|
+
class GeneratingSlugWithValidationSkippedTest < TestCaseClass
|
484
|
+
|
485
|
+
include FriendlyId::Test
|
486
|
+
|
487
|
+
class Journalist < ActiveRecord::Base
|
488
|
+
extend FriendlyId
|
489
|
+
friendly_id :name, :use => :slugged
|
490
|
+
end
|
491
|
+
|
492
|
+
test "should generate slug when skipping validation" do
|
493
|
+
transaction do
|
494
|
+
m1 = Journalist.new
|
495
|
+
m1.name = 'Bob Timesletter'
|
496
|
+
m1.save(validate: false)
|
497
|
+
assert_equal 'bob-timesletter', m1.slug
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
test "should generate slug when #valid? called" do
|
502
|
+
transaction do
|
503
|
+
m1 = Journalist.new
|
504
|
+
m1.name = 'Bob Timesletter'
|
505
|
+
m1.valid?
|
506
|
+
m1.save(validate: false)
|
507
|
+
assert_equal 'bob-timesletter', m1.slug
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
end
|
512
|
+
|
482
513
|
class ToParamTest < TestCaseClass
|
483
514
|
|
484
515
|
include FriendlyId::Test
|
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.4.
|
4
|
+
version: 5.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
Hsej0MQ3drCB1eA4c9OXdCUQJnY2aLTq3uNvTbZvoTgWK55eq3KLBJ4zzoKZ4tBX
|
36
36
|
/HIFI/fEwYlI1Ji3oikUrHkc4rWgaQ==
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2021-01-07 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: activerecord
|
@@ -253,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
253
253
|
- !ruby/object:Gem::Version
|
254
254
|
version: '0'
|
255
255
|
requirements: []
|
256
|
-
rubygems_version: 3.
|
256
|
+
rubygems_version: 3.2.3
|
257
257
|
signing_key:
|
258
258
|
specification_version: 4
|
259
259
|
summary: A comprehensive slugging and pretty-URL plugin.
|
metadata.gz.sig
CHANGED
Binary file
|