friendly_id 5.4.1 → 5.4.2

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
  SHA256:
3
- metadata.gz: ba26f9f615f068d0094f6646a6c6a5aceef44b59bde321aa168542b62420402f
4
- data.tar.gz: 155666a337c2162adc31c2b3337867a7086b63cba390d6d9c6ca8486b7d663d6
3
+ metadata.gz: 21ddfb374efbecb41ddb5164a5f0fbb4df5838edfcb13a8e7d8d6caa1b378f34
4
+ data.tar.gz: 363955e55e33b9b15d59099f1b6ac00d88f32e0b3835f1dfd6fcf718aad7ac7f
5
5
  SHA512:
6
- metadata.gz: bc67ddc3c8940a7b0bcf0c918c0f5f398e1f484d72fde5fa7f1136035d34ac77a25b0db3ac4070fc0abd21abe926e2d15bc9f536e4f57ddb0dcd84c4f787b1b0
7
- data.tar.gz: 1e590565fff83c890ee04dede81e518c98912214dc3122690763ee1731559fd337421bd05c4d201224cddd67891416054a81e7d8b0bbc24acfc2e6661e5ebe03
6
+ metadata.gz: d966763a10e683b815681576ef71c720caeafee88c49f866f912cae1a2aae12a33fd00bfc93f2d0eb7204ae2b91c514613edf34996119519613452b0ce0cdfb1
7
+ data.tar.gz: f8e8522f7f4b1c8a32bc8fd58c719d8376beb3325f2adfbca0554f7ec63a2742d5ab5b7128bbf2fa3f106075f5f89af590843c36bf3924d975674bada3673ca9
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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.x', '2.6.x', '2.5.x' ]
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
- - id: cache-bundler
28
- uses: actions/cache@v2
21
+ - uses: ruby/setup-ruby@v1
29
22
  with:
30
- path: vendor/bundle
31
- key: ${{ matrix.ruby }}-gem-${{ hashFiles(format('gemfiles/Gemfile.rails-{0}.rb', matrix.gemfile)) }}
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 }}
@@ -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
- raise_not_found_exception id
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.downcase)
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') then
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
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module FriendlyId
2
- VERSION = '5.4.1'.freeze
2
+ VERSION = '5.4.2'.freeze
3
3
  end
@@ -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
@@ -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.1
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: 2020-11-06 00:00:00.000000000 Z
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.1.4
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