friendly_id 5.2.3 → 5.2.4

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: 8ecc233dd377f5400a788a6a6fb7d37e2f4b200c
4
- data.tar.gz: 9c848d7c0f238d70577cb0737b1f6411e779a6d5
3
+ metadata.gz: 19856ab4f2e02ba7eed649beef7728be7eae0a58
4
+ data.tar.gz: bcf94acb37ff90b70916a96a34a2035570490128
5
5
  SHA512:
6
- metadata.gz: 4c0a2db2212245e2dcadd50a6f62e3970a10ca72d7230e92cebf31a03da6772c23d2203303e08ff51ed9c9985f234310e01db91f0baa79c663c9756b84181b7a
7
- data.tar.gz: cc539ec2396d5736499c3852d0bd967c10d1d6d0ec3afd63b137634e9ac7f6365d7b073895c5297390a42ad74a9cb363064c81c317ad899f3e44f6f15a312f19
6
+ metadata.gz: 41b11ab959bcf15522a627431421bdb4542fd8768ee1695d6bf68d2351f479c4cd49e6f42e9b46a8f6aac0557bf199b8ad58582c02b049624204e12283740643
7
+ data.tar.gz: 221d38007de3e624191d6905bd0430dc90bce1a9b1212cc20e8bb9bfbd06aa60fc8e0e44c74ec52b9d424210806683ed39446bd623eae09cc07d0542f58db0e6
@@ -6,7 +6,7 @@ rvm:
6
6
  - 2.3.0
7
7
  - 2.2.0
8
8
  - 2.1.0
9
- - jruby-9.0.4.0
9
+ - jruby-9.1.13.0
10
10
 
11
11
  env:
12
12
  - DB=postgres
@@ -17,12 +17,24 @@ gemfile:
17
17
  - gemfiles/Gemfile.rails-4.1.rb
18
18
  - gemfiles/Gemfile.rails-4.2.rb
19
19
  - gemfiles/Gemfile.rails-5.0.rb
20
+ - gemfiles/Gemfile.rails-5.1.rb
21
+ - gemfiles/Gemfile.rails-5.2.rb
20
22
 
21
23
  before_install:
22
24
  - gem update bundler
23
25
 
24
26
  matrix:
25
27
  exclude:
28
+ - rvm: 2.1.0
29
+ gemfile: gemfiles/Gemfile.rails-5.2.rb
30
+ - rvm: 2.2.0
31
+ gemfile: gemfiles/Gemfile.rails-5.2.rb
32
+ - rvm: jruby-9.1.13.0
33
+ gemfile: gemfiles/Gemfile.rails-5.2.rb
34
+ - rvm: 2.1.0
35
+ gemfile: gemfiles/Gemfile.rails-5.1.rb
36
+ - rvm: 2.2.0
37
+ gemfile: gemfiles/Gemfile.rails-5.1.rb
26
38
  - rvm: 2.1.0
27
39
  gemfile: gemfiles/Gemfile.rails-5.0.rb
28
40
  - rvm: 2.2.0
@@ -31,6 +43,11 @@ matrix:
31
43
  gemfile: gemfiles/Gemfile.rails-4.0.rb
32
44
  - rvm: 2.4.0
33
45
  gemfile: gemfiles/Gemfile.rails-4.1.rb
46
+ allow_failures:
47
+ - rvm: jruby-9.1.13.0
48
+ gemfile: gemfiles/Gemfile.rails-5.1.rb
49
+ - rvm: jruby-9.1.13.0
50
+ gemfile: gemfiles/Gemfile.rails-5.0.rb
34
51
 
35
52
  sudo: false
36
53
 
@@ -3,6 +3,18 @@
3
3
  We would like to think our many [contributors](https://github.com/norman/friendly_id/graphs/contributors) for
4
4
  suggestions, ideas and improvements to FriendlyId.
5
5
 
6
+ ## 5.2.4 (2018-04-24)
7
+
8
+ * Fix compatibility with Rails versions 4.0 -> 5.2. ([#863](https://github.com/norman/friendly_id/pull/863)).
9
+ * Refactor `History::FinderMethods` to use base implementation. ([#853](https://github.com/norman/friendly_id/pull/853)).
10
+ * Defer loading of ActiveRecord to avoid config issues. ([#852](https://github.com/norman/friendly_id/pull/852)).
11
+ * Ensure compatibility with paranoid deletion libraries. ([#838](https://github.com/norman/friendly_id/pull/838)).
12
+ * Add treat_reserved_as_conflict option to initializer ([#847](https://github.com/norman/friendly_id/pull/847)).
13
+
14
+ ## 5.2.3 (2017-09-22)
15
+
16
+ * Added option to treat reserved words as conflicts ([#831](https://github.com/norman/friendly_id/pull/831)).
17
+
6
18
  ## 5.2.2 (2017-09-13)
7
19
 
8
20
  * Prevent warning on db:migrate in Rails 5.1 ([#826](https://github.com/norman/friendly_id/pull/826)).
@@ -24,7 +36,7 @@ suggestions, ideas and improvements to FriendlyId.
24
36
  * Don't calculate all changes just to check if the param field has changed ([#667](https://github.com/norman/friendly_id/pull/667)).
25
37
  * Don't set or change slug when unrelated validation failures block the record from being saved ([#642](https://github.com/norman/friendly_id/issues/642)).
26
38
  * Fix order dependence bug between history and finders modules ([#718](https://github.com/norman/friendly_id/pull/718))
27
- * Added ability to conditionally turn off :dependent => :destory on FriendlyId::Slugs([#724](https://github.com/norman/friendly_id/pull/724))
39
+ * Added ability to conditionally turn off `:dependent => :destroy` on FriendlyId::Slugs([#724](https://github.com/norman/friendly_id/pull/724))
28
40
  * Add support for Rails 5. ([#728](https://github.com/norman/friendly_id/pull/728))
29
41
  * Allow per-model conditional disabling of friendly path generation using a :routes option to friendly_id ([#735](https://github.com/norman/friendly_id/pull/735))
30
42
 
data/README.md CHANGED
@@ -2,18 +2,6 @@
2
2
  [![Code Climate](https://codeclimate.com/github/norman/friendly_id.svg)](https://codeclimate.com/github/norman/friendly_id)
3
3
  [![Inline docs](http://inch-ci.org/github/norman/friendly_id.svg?branch=master)](http://inch-ci.org/github/norman/friendly_id)
4
4
 
5
- **GETTING HELP**
6
-
7
- Please ask questions on [Stack
8
- Overflow](http://stackoverflow.com/questions/tagged/friendly-id) using the
9
- "friendly-id" tag. Prior to asking, search and see if your question has
10
- already been answered.
11
-
12
- Please only post issues in Github issues for actual bugs.
13
-
14
- I am asking people to do this because the same questions keep getting asked
15
- over and over and over again in the issues.
16
-
17
5
  # FriendlyId
18
6
 
19
7
  **For the most complete, user-friendly documentation, see the [FriendlyId Guide](http://norman.github.io/friendly_id/file.Guide.html).**
@@ -31,185 +19,84 @@ instead of:
31
19
  http://example.com/states/4323454
32
20
 
33
21
 
34
- ## FriendlyId Features
35
-
36
- FriendlyId offers many advanced features, including: slug history and
37
- versioning, i18n, scoped slugs, reserved words, and custom slug generators.
38
-
39
- ### What Changed in Version 5.1
40
-
41
- 5.1 is a bugfix release, but bumps the minor version because some applications may be dependent
42
- on the previously buggy behavior. The changes include:
43
-
44
- * Blank strings can no longer be used as slugs.
45
- * When the first slug candidate is rejected because it is reserved, additional candidates will
46
- now be considered before marking the record as invalid.
47
- * The `:finders` module is now compatible with Rails 4.2.
48
-
49
- ### What Changed in Version 5.0
50
-
51
- As of version 5.0, FriendlyId uses [semantic versioning](http://semver.org/). Therefore, as you might
52
- infer from the version number, 5.0 introduces changes incompatible with 4.0.
53
-
54
- The most important changes are:
55
-
56
- * Finders are no longer overridden by default. If you want to do friendly finds,
57
- you must do `Model.friendly.find` rather than `Model.find`. You can however
58
- restore FriendlyId 4-style finders by using the `:finders` addon:
59
-
60
- ```ruby
61
- friendly_id :foo, use: :slugged # you must do MyClass.friendly.find('bar')
62
- # or...
63
- friendly_id :foo, use: [:slugged, :finders] # you can now do MyClass.find('bar')
64
- ```
65
- * A new "candidates" functionality which makes it easy to set up a list of
66
- alternate slugs that can be used to uniquely distinguish records, rather than
67
- appending a sequence. For example:
68
-
69
- ```ruby
70
- class Restaurant < ActiveRecord::Base
71
- extend FriendlyId
72
- friendly_id :slug_candidates, use: :slugged
73
-
74
- # Try building a slug based on the following fields in
75
- # increasing order of specificity.
76
- def slug_candidates
77
- [
78
- :name,
79
- [:name, :city],
80
- [:name, :street, :city],
81
- [:name, :street_number, :street, :city]
82
- ]
83
- end
84
- end
85
- ```
86
- * Now that candidates have been added, FriendlyId no longer uses a numeric
87
- sequence to differentiate conflicting slug, but rather a UUID (e.g. something
88
- like `2bc08962-b3dd-4f29-b2e6-244710c86106`). This makes the
89
- codebase simpler and more reliable when running concurrently, at the expense
90
- of uglier ids being generated when there are conflicts.
91
- * The default sequence separator has been changed from two dashes to one dash.
92
- * Slugs are no longer regenerated when a record is saved. If you want to regenerate
93
- a slug, you must explicitly set the slug column to nil:
94
-
95
- ```ruby
96
- restaurant.friendly_id # joes-diner
97
- restaurant.name = "The Plaza Diner"
98
- restaurant.save!
99
- restaurant.friendly_id # joes-diner
100
- restaurant.slug = nil
101
- restaurant.save!
102
- restaurant.friendly_id # the-plaza-diner
103
- ```
104
-
105
- You can restore some of the old behavior by overriding the
106
- `should_generate_new_friendly_id?` method.
107
- * The `friendly_id` Rails generator now generates an initializer showing you
108
- how to do some common global configuration.
109
- * The Globalize plugin has moved to a [separate gem](https://github.com/norman/friendly_id-globalize) (currently in alpha).
110
- * The `:reserved` module no longer includes any default reserved words.
111
- Previously it blocked "edit" and "new" everywhere. The default word list has
112
- been moved to `config/initializers/friendly_id.rb` and now includes many more
113
- words.
114
- * The `:history` and `:scoped` addons can now be used together.
115
- * Since it now requires Rails 4, FriendlyId also now requires Ruby 1.9.3 or
116
- higher.
117
-
118
- #### Upgrading from FriendlyId 4.0
119
-
120
- Run `rails generate friendly_id --skip-migration` and edit the initializer
121
- generated in `config/initializers/friendly_id.rb`. This file contains notes
122
- describing how to restore (or not) some of the defaults from FriendlyId 4.0.
123
-
124
- If you want to use the `:history` and `:scoped` addons together, you must add a
125
- `:scope` column to your friendly_id_slugs table and replace the unique index on
126
- `:slug` and `:sluggable_type` with a unique index on those two columns, plus
127
- the new `:scope` column.
128
-
129
- A migration like this should be sufficient:
130
-
131
- ```ruby
132
- add_column :friendly_id_slugs, :scope, :string
133
- remove_index :friendly_id_slugs, [:slug, :sluggable_type]
134
- add_index :friendly_id_slugs, [:slug, :sluggable_type]
135
- add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], unique: true
136
- ```
137
-
138
- ## Articles
22
+ ## Getting Help
139
23
 
140
- [Migrating an ad-hoc URL slug system to FriendlyId](http://olivierlacan.com/posts/migrating-an-ad-hoc-url-slug-system-to-friendly-id/)
141
- [Pretty URLs with FriendlyId](http://railscasts.com/episodes/314-pretty-urls-with-friendlyid)
24
+ Ask questions on [Stack Overflow](http://stackoverflow.com/questions/tagged/friendly-id)
25
+ using the "friendly-id" tag, and for bugs have a look at [the bug section](https://github.com/norman/friendly_id#bugs)
142
26
 
143
- ## Docs
144
-
145
- The most current docs from the master branch can always be found
146
- [here](http://norman.github.io/friendly_id).
147
-
148
- Docs for older versions are also available:
27
+ ## FriendlyId Features
149
28
 
150
- * [5.0](http://norman.github.io/friendly_id/5.0/)
151
- * [4.0](http://norman.github.io/friendly_id/4.0/)
152
- * [3.3](http://norman.github.io/friendly_id/3.3/)
153
- * [2.3](http://norman.github.io/friendly_id/2.3/)
29
+ FriendlyId offers many advanced features, including:
154
30
 
155
- The best place to start is with the
156
- [Guide](http://norman.github.io/friendly_id/file.Guide.html),
157
- which compiles the top-level RDocs into one outlined document.
31
+ * slug history and versioning
32
+ * i18n
33
+ * scoped slugs
34
+ * reserved words
35
+ * custom slug generators
158
36
 
159
- For a getting started video, you may want to watch [GoRails #9](https://gorails.com/episodes/pretty-urls-with-friendly-id)
37
+ ## Usage
160
38
 
161
- You might also want to watch Ryan Bates's [Railscast on FriendlyId](http://railscasts.com/episodes/314-pretty-urls-with-friendlyid),
162
- which is now somewhat outdated but still relevant.
39
+ Add this line to your application's Gemfile:
163
40
 
41
+ ```ruby
42
+ gem 'friendly_id', '~> 5.1.0' # Note: You MUST use 5.0.0 or greater for Rails 4.0+
43
+ ```
164
44
 
165
- ## Rails Quickstart
45
+ And then execute:
166
46
 
167
47
  ```shell
168
- rails new my_app
169
- cd my_app
170
- ```
171
- ```ruby
172
- # Gemfile
173
- gem 'friendly_id', '~> 5.1.0' # Note: You MUST use 5.0.0 or greater for Rails 4.0+
48
+ bundle install
174
49
  ```
50
+
51
+ Generate the friendly configuration file
52
+
175
53
  ```shell
176
54
  rails generate friendly_id
177
55
  ```
56
+
178
57
  >Temp solution for Rails 5.1+ : Before running the migration, go into the generated migration file and specify the Rails version:
179
58
  `class CreateFriendlyIdSlugs < ActiveRecord::Migration[5.1]`
59
+
60
+ Run the migration scripts
61
+
180
62
  ```shell
181
- rails generate scaffold user name:string slug:string:uniq
182
- rake db:migrate
63
+ rails db:migrate
183
64
  ```
65
+
66
+ Edit the `app/models/user.rb` file as the following:
67
+
184
68
  ```ruby
185
- # edit app/models/user.rb
186
69
  class User < ApplicationRecord
187
70
  extend FriendlyId
188
71
  friendly_id :name, use: :slugged
189
72
  end
73
+ ```
190
74
 
191
- User.create! name: "Joe Schmoe"
75
+ Edit the `app/controllers/users_controller.rb` file and replace `User.find` by `User.friendly.find`
192
76
 
193
- # Change User.find to User.friendly.find in your controller
194
- User.friendly.find(params[:id])
77
+ ```ruby
78
+ class UserController < ApplicationController
79
+ def show
80
+ @user = User.friendly.find(params[:id])
81
+ end
82
+ end
195
83
  ```
196
- ```shell
197
- rails server
198
84
 
199
- GET http://localhost:3000/users/joe-schmoe
200
- ```
85
+ Now when you create a new user like the following:
86
+
201
87
  ```ruby
202
- # If you're adding FriendlyId to an existing app and need
203
- # to generate slugs for existing users, do this from the
204
- # console, runner, or add a Rake task:
205
- User.find_each(&:save)
88
+ User.create! name: "Joe Schmoe"
206
89
  ```
207
90
 
208
- ## Benchmarks
91
+ You can then access the user show page using the URL http://localhost:3000/users/joe-schmoe.
92
+
209
93
 
210
- The latest benchmarks for FriendlyId are maintained
211
- [here](http://bit.ly/friendly-id-benchmarks).
94
+ If you're adding FriendlyId to an existing app and need to generate slugs for
95
+ existing users, do this from the console, runner, or add a Rake task:
212
96
 
97
+ ```ruby
98
+ User.find_each(&:save)
99
+ ```
213
100
 
214
101
  ## Bugs
215
102
 
@@ -0,0 +1,115 @@
1
+ ## Articles
2
+
3
+ * [Migrating an ad-hoc URL slug system to FriendlyId](http://olivierlacan.com/posts/migrating-an-ad-hoc-url-slug-system-to-friendly-id/)
4
+ * [Pretty URLs with FriendlyId](http://railscasts.com/episodes/314-pretty-urls-with-friendlyid)
5
+
6
+ ## Docs
7
+
8
+ The most current docs from the master branch can always be found
9
+ [here](http://norman.github.io/friendly_id).
10
+
11
+ Docs for older versions are also available:
12
+
13
+ * [5.0](http://norman.github.io/friendly_id/5.0/)
14
+ * [4.0](http://norman.github.io/friendly_id/4.0/)
15
+ * [3.3](http://norman.github.io/friendly_id/3.3/)
16
+ * [2.3](http://norman.github.io/friendly_id/2.3/)
17
+
18
+ ## What Changed in Version 5.1
19
+
20
+ 5.1 is a bugfix release, but bumps the minor version because some applications may be dependent
21
+ on the previously buggy behavior. The changes include:
22
+
23
+ * Blank strings can no longer be used as slugs.
24
+ * When the first slug candidate is rejected because it is reserved, additional candidates will
25
+ now be considered before marking the record as invalid.
26
+ * The `:finders` module is now compatible with Rails 4.2.
27
+
28
+ ## What Changed in Version 5.0
29
+
30
+ As of version 5.0, FriendlyId uses [semantic versioning](http://semver.org/). Therefore, as you might
31
+ infer from the version number, 5.0 introduces changes incompatible with 4.0.
32
+
33
+ The most important changes are:
34
+
35
+ * Finders are no longer overridden by default. If you want to do friendly finds,
36
+ you must do `Model.friendly.find` rather than `Model.find`. You can however
37
+ restore FriendlyId 4-style finders by using the `:finders` addon:
38
+
39
+ ```ruby
40
+ friendly_id :foo, use: :slugged # you must do MyClass.friendly.find('bar')
41
+ # or...
42
+ friendly_id :foo, use: [:slugged, :finders] # you can now do MyClass.find('bar')
43
+ ```
44
+ * A new "candidates" functionality which makes it easy to set up a list of
45
+ alternate slugs that can be used to uniquely distinguish records, rather than
46
+ appending a sequence. For example:
47
+
48
+ ```ruby
49
+ class Restaurant < ActiveRecord::Base
50
+ extend FriendlyId
51
+ friendly_id :slug_candidates, use: :slugged
52
+
53
+ # Try building a slug based on the following fields in
54
+ # increasing order of specificity.
55
+ def slug_candidates
56
+ [
57
+ :name,
58
+ [:name, :city],
59
+ [:name, :street, :city],
60
+ [:name, :street_number, :street, :city]
61
+ ]
62
+ end
63
+ end
64
+ ```
65
+ * Now that candidates have been added, FriendlyId no longer uses a numeric
66
+ sequence to differentiate conflicting slug, but rather a UUID (e.g. something
67
+ like `2bc08962-b3dd-4f29-b2e6-244710c86106`). This makes the
68
+ codebase simpler and more reliable when running concurrently, at the expense
69
+ of uglier ids being generated when there are conflicts.
70
+ * The default sequence separator has been changed from two dashes to one dash.
71
+ * Slugs are no longer regenerated when a record is saved. If you want to regenerate
72
+ a slug, you must explicitly set the slug column to nil:
73
+
74
+ ```ruby
75
+ restaurant.friendly_id # joes-diner
76
+ restaurant.name = "The Plaza Diner"
77
+ restaurant.save!
78
+ restaurant.friendly_id # joes-diner
79
+ restaurant.slug = nil
80
+ restaurant.save!
81
+ restaurant.friendly_id # the-plaza-diner
82
+ ```
83
+
84
+ You can restore some of the old behavior by overriding the
85
+ `should_generate_new_friendly_id?` method.
86
+ * The `friendly_id` Rails generator now generates an initializer showing you
87
+ how to do some common global configuration.
88
+ * The Globalize plugin has moved to a [separate gem](https://github.com/norman/friendly_id-globalize) (currently in alpha).
89
+ * The `:reserved` module no longer includes any default reserved words.
90
+ Previously it blocked "edit" and "new" everywhere. The default word list has
91
+ been moved to `config/initializers/friendly_id.rb` and now includes many more
92
+ words.
93
+ * The `:history` and `:scoped` addons can now be used together.
94
+ * Since it now requires Rails 4, FriendlyId also now requires Ruby 1.9.3 or
95
+ higher.
96
+
97
+ ## Upgrading from FriendlyId 4.0
98
+
99
+ Run `rails generate friendly_id --skip-migration` and edit the initializer
100
+ generated in `config/initializers/friendly_id.rb`. This file contains notes
101
+ describing how to restore (or not) some of the defaults from FriendlyId 4.0.
102
+
103
+ If you want to use the `:history` and `:scoped` addons together, you must add a
104
+ `:scope` column to your friendly_id_slugs table and replace the unique index on
105
+ `:slug` and `:sluggable_type` with a unique index on those two columns, plus
106
+ the new `:scope` column.
107
+
108
+ A migration like this should be sufficient:
109
+
110
+ ```ruby
111
+ add_column :friendly_id_slugs, :scope, :string
112
+ remove_index :friendly_id_slugs, [:slug, :sluggable_type]
113
+ add_index :friendly_id_slugs, [:slug, :sluggable_type]
114
+ add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], unique: true
115
+ ```
@@ -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', '~> 5.3'
24
24
  s.add_development_dependency 'mocha', '~> 1.1'
25
25
  s.add_development_dependency 'yard'
@@ -18,7 +18,7 @@ group :development, :test do
18
18
  platforms :ruby, :rbx do
19
19
  gem 'sqlite3'
20
20
  gem 'mysql2', '~> 0.3.10'
21
- gem 'pg'
21
+ gem 'pg', '~> 0.15'
22
22
  gem 'redcarpet'
23
23
  end
24
24
 
@@ -17,7 +17,7 @@ group :development, :test do
17
17
  platforms :ruby, :rbx do
18
18
  gem 'sqlite3'
19
19
  gem 'mysql2', '~> 0.3.13'
20
- gem 'pg'
20
+ gem 'pg', '~> 0.15'
21
21
  gem 'redcarpet'
22
22
  end
23
23
 
@@ -16,8 +16,8 @@ group :development, :test do
16
16
 
17
17
  platforms :ruby, :rbx do
18
18
  gem 'sqlite3'
19
- gem 'mysql2'
20
- gem 'pg'
19
+ gem 'mysql2', '~> 0.4.10'
20
+ gem 'pg', '~> 0.15'
21
21
  gem 'redcarpet'
22
22
  end
23
23
 
@@ -9,8 +9,8 @@ gem 'i18n', '~> 0.7.0'
9
9
  # Database Configuration
10
10
  group :development, :test do
11
11
  platforms :jruby do
12
- gem 'activerecord-jdbcmysql-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter.git', branch: 'rails-5'
13
- gem 'activerecord-jdbcpostgresql-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter.git', branch: 'rails-5'
12
+ gem 'activerecord-jdbcmysql-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', branch: '50-stable'
13
+ gem 'activerecord-jdbcpostgresql-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', branch: '50-stable'
14
14
  gem 'kramdown'
15
15
  end
16
16
 
@@ -0,0 +1,27 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 5.1.0'
6
+ gem 'railties', '~> 5.1.0'
7
+
8
+ # Database Configuration
9
+ group :development, :test do
10
+ platforms :jruby do
11
+ gem 'activerecord-jdbcmysql-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', branch: 'master'
12
+ gem 'activerecord-jdbcpostgresql-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', branch: 'master'
13
+ gem 'kramdown'
14
+ end
15
+
16
+ platforms :ruby, :rbx do
17
+ gem 'sqlite3'
18
+ gem 'mysql2'
19
+ gem 'pg'
20
+ gem 'redcarpet'
21
+ end
22
+
23
+ platforms :rbx do
24
+ gem 'rubysl', '~> 2.0'
25
+ gem 'rubinius-developer_tools'
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 5.2.0'
6
+ gem 'railties', '~> 5.2.0'
7
+
8
+ # Database Configuration
9
+ group :development, :test do
10
+ platforms :jruby do
11
+ gem 'activerecord-jdbcmysql-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', branch: 'master'
12
+ gem 'activerecord-jdbcpostgresql-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', branch: 'master'
13
+ gem 'kramdown'
14
+ end
15
+
16
+ platforms :ruby, :rbx do
17
+ gem 'sqlite3'
18
+ gem 'mysql2'
19
+ gem 'pg'
20
+ gem 'redcarpet'
21
+ end
22
+
23
+ platforms :rbx do
24
+ gem 'rubysl', '~> 2.0'
25
+ gem 'rubinius-developer_tools'
26
+ end
27
+ end
@@ -63,8 +63,6 @@ module FriendlyId
63
63
  slug.present?
64
64
  end
65
65
 
66
- private
67
-
68
66
  def reserved?(slug)
69
67
  config = @object.friendly_id_config
70
68
  return false unless config.uses? ::FriendlyId::Reserved
@@ -9,7 +9,7 @@ module FriendlyId
9
9
  # id matching '123' and then fall back to looking for a record with the
10
10
  # numeric id '123'.
11
11
  #
12
- # Since FriendlyId 5.0, if the id is a numeric string like '123-foo' it
12
+ # Since FriendlyId 5.0, if the id is a nonnumeric string like '123-foo' it
13
13
  # will *only* search by friendly id and not fall back to the regular find
14
14
  # method.
15
15
  #
@@ -50,7 +50,7 @@ module FriendlyId
50
50
  when :integer
51
51
  Integer(id, 10) rescue false
52
52
  when :uuid
53
- id.match /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/
53
+ id.match(/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/)
54
54
  else
55
55
  true
56
56
  end
@@ -72,7 +72,7 @@ method.
72
72
  # Configures the model instance to use the History add-on.
73
73
  def self.included(model_class)
74
74
  model_class.class_eval do
75
- has_many :slugs, -> {order("#{Slug.quoted_table_name}.id DESC")}, {
75
+ has_many :slugs, -> {order(id: :desc)}, {
76
76
  :as => :sluggable,
77
77
  :dependent => @friendly_id_config.dependent_value,
78
78
  :class_name => Slug.to_s
@@ -86,14 +86,13 @@ method.
86
86
  include ::FriendlyId::FinderMethods
87
87
 
88
88
  def exists_by_friendly_id?(id)
89
- where(arel_table[friendly_id_config.query_field].eq(id)).exists? || joins(:slugs).where(slug_history_clause(id)).exists?
89
+ super || joins(:slugs).where(slug_history_clause(id)).exists?
90
90
  end
91
91
 
92
92
  private
93
93
 
94
94
  def first_by_friendly_id(id)
95
- matching_record = where(friendly_id_config.query_field => id).first
96
- matching_record || slug_table_record(id)
95
+ super || slug_table_record(id)
97
96
  end
98
97
 
99
98
  def slug_table_record(id)
@@ -18,6 +18,12 @@ FriendlyId.defaults do |config|
18
18
 
19
19
  config.reserved_words = %w(new edit index session login logout users admin
20
20
  stylesheets assets javascripts images)
21
+
22
+ # This adds an option to to treat reserved words as conflicts rather than exceptions.
23
+ # When there is no good candidate, a UUID will be appended, matching the existing
24
+ # conflict behavior.
25
+
26
+ # config.treat_reserved_as_conflict = true
21
27
 
22
28
  # ## Friendly Finders
23
29
  #
@@ -76,7 +82,12 @@ FriendlyId.defaults do |config|
76
82
  # behavior by overriding the `should_generate_new_friendly_id?` method that
77
83
  # FriendlyId adds to your model. The change below makes FriendlyId 5.0 behave
78
84
  # more like 4.0.
85
+ # Note: Use(include) Slugged module in the config if using the anonymous module.
86
+ # If you have `friendly_id :name, use: slugged` in the model, Slugged module
87
+ # is included after the anonymous module defined in the initializer, so it
88
+ # overrides the `should_generate_new_friendly_id?` method from the anonymous module.
79
89
  #
90
+ # config.use :slugged
80
91
  # config.use Module.new {
81
92
  # def should_generate_new_friendly_id?
82
93
  # slug.blank? || <your_column_name_here>_changed?
@@ -1,4 +1,11 @@
1
- class CreateFriendlyIdSlugs < ActiveRecord::Migration
1
+ migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration[4.2]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class CreateFriendlyIdSlugs < migration_class
2
9
  def change
3
10
  create_table :friendly_id_slugs do |t|
4
11
  t.string :slug, :null => false
@@ -2,7 +2,6 @@ module FriendlyId
2
2
  # Instances of these classes will never be considered a friendly id.
3
3
  # @see FriendlyId::ObjectUtils#friendly_id
4
4
  UNFRIENDLY_CLASSES = [
5
- ActiveRecord::Base,
6
5
  Array,
7
6
  FalseClass,
8
7
  Hash,
@@ -59,6 +58,10 @@ module FriendlyId
59
58
  true
60
59
  end
61
60
  end
61
+
62
+ def self.mark_as_unfriendly(klass)
63
+ klass.send(:include, FriendlyId::UnfriendlyUtils)
64
+ end
62
65
  end
63
66
 
64
67
  Object.send :include, FriendlyId::ObjectUtils
@@ -66,4 +69,8 @@ Object.send :include, FriendlyId::ObjectUtils
66
69
  # Considered unfriendly if object is an instance of an unfriendly class or
67
70
  # one of its descendants.
68
71
 
69
- FriendlyId::UNFRIENDLY_CLASSES.each { |klass| klass.send(:include, FriendlyId::UnfriendlyUtils) }
72
+ FriendlyId::UNFRIENDLY_CLASSES.each { |klass| FriendlyId.mark_as_unfriendly(klass) }
73
+
74
+ ActiveSupport.on_load(:active_record) do
75
+ FriendlyId.mark_as_unfriendly(ActiveRecord::Base)
76
+ end
@@ -47,7 +47,7 @@ module FriendlyId
47
47
  def slug_conflicts
48
48
  scope.
49
49
  where(conflict_query, slug, sequential_slug_matcher).
50
- order(ordering_query).pluck(slug_column)
50
+ order(Arel.sql(ordering_query)).pluck(Arel.sql(slug_column))
51
51
  end
52
52
 
53
53
  def conflict_query
@@ -5,6 +5,10 @@ module FriendlyId
5
5
  class Slug < ActiveRecord::Base
6
6
  belongs_to :sluggable, :polymorphic => true
7
7
 
8
+ def sluggable
9
+ sluggable_type.constantize.unscoped { super }
10
+ end
11
+
8
12
  def to_param
9
13
  slug
10
14
  end
@@ -1,3 +1,3 @@
1
1
  module FriendlyId
2
- VERSION = '5.2.3'.freeze
2
+ VERSION = '5.2.4'.freeze
3
3
  end
@@ -38,6 +38,10 @@ if ENV["LOG"]
38
38
  ActiveRecord::Base.logger = Logger.new($stdout)
39
39
  end
40
40
 
41
+ if ActiveSupport::VERSION::STRING >= '4.2'
42
+ ActiveSupport.test_order = :random
43
+ end
44
+
41
45
  module FriendlyId
42
46
  module Test
43
47
 
@@ -172,7 +172,7 @@ class HistoryTestWithAutomaticSlugRegeneration < HistoryTest
172
172
  end
173
173
  end
174
174
 
175
- class DependentDestroyTest < HistoryTest
175
+ class DependentDestroyTest < TestCaseClass
176
176
 
177
177
  include FriendlyId::Test
178
178
 
@@ -211,6 +211,37 @@ class DependentDestroyTest < HistoryTest
211
211
  end
212
212
  end
213
213
 
214
+ if ActiveRecord::VERSION::STRING >= '5.0'
215
+ class HistoryTestWithParanoidDeletes < HistoryTest
216
+ class ParanoidRecord < ActiveRecord::Base
217
+ extend FriendlyId
218
+ friendly_id :name, :use => :history, :dependent => false
219
+
220
+ default_scope { where(deleted_at: nil) }
221
+ end
222
+
223
+ def model_class
224
+ ParanoidRecord
225
+ end
226
+
227
+ test 'slug should have a sluggable even when soft deleted by a library' do
228
+ transaction do
229
+ assert FriendlyId::Slug.find_by_slug('paranoid').nil?
230
+ record = model_class.create(name: 'paranoid')
231
+ assert FriendlyId::Slug.find_by_slug('paranoid').present?
232
+
233
+ record.update_attribute(:deleted_at, Time.now)
234
+
235
+ orphan_slug = FriendlyId::Slug.find_by_slug('paranoid')
236
+ assert orphan_slug.present?, 'Orphaned slug should exist'
237
+
238
+ assert orphan_slug.valid?, "Errors: #{orphan_slug.errors.full_messages}"
239
+ assert orphan_slug.sluggable.present?, 'Orphaned slug should still find corresponding paranoid sluggable'
240
+ end
241
+ end
242
+ end
243
+ end
244
+
214
245
  class HistoryTestWithSti < HistoryTest
215
246
  class Journalist < ActiveRecord::Base
216
247
  extend FriendlyId
@@ -248,7 +279,7 @@ class HistoryTestWithFriendlyFinders < HistoryTest
248
279
  begin
249
280
  assert model_class.find(old_friendly_id)
250
281
  assert model_class.exists?(old_friendly_id), "should exist? by old id for #{model_class.name}"
251
- rescue ActiveRecord::RecordNotFound => e
282
+ rescue ActiveRecord::RecordNotFound
252
283
  flunk "Could not find record by old id for #{model_class.name}"
253
284
  end
254
285
  end
@@ -356,4 +387,4 @@ class ScopedHistoryTest < TestCaseClass
356
387
  assert_equal record.slug, second_record.slug
357
388
  end
358
389
  end
359
- end
390
+ end
@@ -19,6 +19,8 @@ class ObjectUtilsTest < TestCaseClass
19
19
  end
20
20
 
21
21
  test "ActiveRecord::Base instances should be unfriendly_ids" do
22
+ FriendlyId.mark_as_unfriendly(ActiveRecord::Base)
23
+
22
24
  model_class = Class.new(ActiveRecord::Base) do
23
25
  self.table_name = "authors"
24
26
  end
@@ -2,7 +2,14 @@ require "friendly_id/migration"
2
2
 
3
3
  module FriendlyId
4
4
  module Test
5
- class Schema < ActiveRecord::Migration
5
+ migration_class =
6
+ if ActiveRecord::VERSION::MAJOR >= 5
7
+ ActiveRecord::Migration[4.2]
8
+ else
9
+ ActiveRecord::Migration
10
+ end
11
+
12
+ class Schema < migration_class
6
13
  class << self
7
14
  def down
8
15
  CreateFriendlyIdSlugs.down
@@ -41,6 +48,12 @@ module FriendlyId
41
48
  add_column table_name, :slug, :string
42
49
  end
43
50
 
51
+ paranoid_tables.each do |table_name|
52
+ add_column table_name, :slug, :string
53
+ add_column table_name, :deleted_at, :datetime
54
+ add_index table_name, :deleted_at
55
+ end
56
+
44
57
  # This will be used to test scopes
45
58
  add_column :novels, :novelist_id, :integer
46
59
  add_column :novels, :publisher_id, :integer
@@ -78,6 +91,10 @@ module FriendlyId
78
91
  %w[journalists articles novelists novels manuals cities]
79
92
  end
80
93
 
94
+ def paranoid_tables
95
+ ["paranoid_records"]
96
+ end
97
+
81
98
  def tables_with_uuid_primary_key
82
99
  ["menu_items"]
83
100
  end
@@ -91,7 +108,7 @@ module FriendlyId
91
108
  end
92
109
 
93
110
  def tables
94
- simple_tables + slugged_tables + scoped_tables
111
+ simple_tables + slugged_tables + scoped_tables + paranoid_tables
95
112
  end
96
113
  end
97
114
  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.3
4
+ version: 5.2.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: 2017-09-21 00:00:00.000000000 Z
12
+ date: 2018-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -43,14 +43,14 @@ dependencies:
43
43
  name: railties
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
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
55
  version: '4.0'
56
56
  - !ruby/object:Gem::Dependency
@@ -158,12 +158,15 @@ files:
158
158
  - MIT-LICENSE
159
159
  - README.md
160
160
  - Rakefile
161
+ - UPGRADING.md
161
162
  - bench.rb
162
163
  - friendly_id.gemspec
163
164
  - gemfiles/Gemfile.rails-4.0.rb
164
165
  - gemfiles/Gemfile.rails-4.1.rb
165
166
  - gemfiles/Gemfile.rails-4.2.rb
166
167
  - gemfiles/Gemfile.rails-5.0.rb
168
+ - gemfiles/Gemfile.rails-5.1.rb
169
+ - gemfiles/Gemfile.rails-5.2.rb
167
170
  - guide.rb
168
171
  - lib/friendly_id.rb
169
172
  - lib/friendly_id/.gitattributes