friendly_id 5.2.4 → 5.5.0
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/dependabot.yml +6 -0
- data/.github/stale.yml +17 -0
- data/.github/workflows/test.yml +58 -0
- data/Changelog.md +41 -0
- data/Gemfile +10 -11
- data/README.md +42 -15
- data/Rakefile +24 -27
- data/bench.rb +30 -27
- data/certs/parndt.pem +27 -0
- data/friendly_id.gemspec +28 -27
- data/gemfiles/Gemfile.rails-5.2.rb +11 -16
- data/gemfiles/Gemfile.rails-6.0.rb +22 -0
- data/gemfiles/Gemfile.rails-6.1.rb +22 -0
- data/gemfiles/Gemfile.rails-7.0.rb +22 -0
- data/guide.rb +5 -5
- data/lib/friendly_id/base.rb +61 -68
- data/lib/friendly_id/candidates.rb +9 -11
- data/lib/friendly_id/configuration.rb +8 -8
- data/lib/friendly_id/finder_methods.rb +72 -13
- data/lib/friendly_id/finders.rb +64 -67
- data/lib/friendly_id/history.rb +72 -66
- data/lib/friendly_id/initializer.rb +5 -5
- data/lib/friendly_id/migration.rb +10 -11
- data/lib/friendly_id/object_utils.rb +2 -2
- data/lib/friendly_id/reserved.rb +28 -32
- data/lib/friendly_id/scoped.rb +105 -103
- data/lib/friendly_id/sequentially_slugged/calculator.rb +69 -0
- data/lib/friendly_id/sequentially_slugged.rb +21 -58
- data/lib/friendly_id/simple_i18n.rb +75 -69
- data/lib/friendly_id/slug.rb +1 -2
- data/lib/friendly_id/slug_generator.rb +1 -3
- data/lib/friendly_id/slugged.rb +236 -239
- data/lib/friendly_id/version.rb +1 -1
- data/lib/friendly_id.rb +41 -45
- data/lib/generators/friendly_id_generator.rb +9 -9
- data/test/base_test.rb +10 -13
- data/test/benchmarks/finders.rb +28 -26
- data/test/benchmarks/object_utils.rb +13 -13
- data/test/candidates_test.rb +17 -18
- data/test/configuration_test.rb +7 -11
- data/test/core_test.rb +1 -2
- data/test/databases.yml +7 -4
- data/test/finders_test.rb +52 -5
- data/test/generator_test.rb +16 -26
- data/test/helper.rb +33 -20
- data/test/history_test.rb +116 -72
- data/test/numeric_slug_test.rb +31 -0
- data/test/object_utils_test.rb +0 -2
- data/test/reserved_test.rb +9 -11
- data/test/schema.rb +5 -4
- data/test/scoped_test.rb +26 -15
- data/test/sequentially_slugged_test.rb +107 -33
- data/test/shared.rb +17 -18
- data/test/simple_i18n_test.rb +23 -13
- data/test/slugged_test.rb +254 -78
- data/test/sti_test.rb +19 -21
- data.tar.gz.sig +0 -0
- metadata +49 -19
- metadata.gz.sig +1 -0
- data/.travis.yml +0 -57
- data/gemfiles/Gemfile.rails-4.0.rb +0 -30
- data/gemfiles/Gemfile.rails-4.1.rb +0 -29
- data/gemfiles/Gemfile.rails-4.2.rb +0 -28
- data/gemfiles/Gemfile.rails-5.0.rb +0 -28
- data/gemfiles/Gemfile.rails-5.1.rb +0 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0b1293d744a87c9988c0ff2dfba773f351cdf62bc24e3b3c73e386310b44d4bb
|
|
4
|
+
data.tar.gz: 1e02363f0abe107ce5165942024ff4cdabfc8b8c18083e0615846c58f5e41252
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7f27736b4ae2218c95c42cde457472a919c81f89d0b899453c351e4b16c2e557c6f44a9dc32ef947123e2228e5588f8bcd1157c60d3ecb4f4195cc4687609b9
|
|
7
|
+
data.tar.gz: bf6b4a73627faa1363a78d70d6a82e3e1ebf2fa1b7979504d0914646325fffc980f9b78508a3a9ad8ab17c93034bc45c2b50cf3d058f33857b4e83a064c605fc
|
checksums.yaml.gz.sig
ADDED
|
Binary file
|
data/.github/FUNDING.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
github: parndt
|
data/.github/stale.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Number of days of inactivity before an issue becomes stale
|
|
2
|
+
daysUntilStale: 84
|
|
3
|
+
# Number of days of inactivity before a stale issue is closed
|
|
4
|
+
daysUntilClose: 7
|
|
5
|
+
# Issues with these labels will never be considered stale
|
|
6
|
+
exemptLabels:
|
|
7
|
+
- pinned
|
|
8
|
+
- security
|
|
9
|
+
# Label to use when marking an issue as stale
|
|
10
|
+
staleLabel: stale
|
|
11
|
+
# Comment to post when marking an issue as stale. Set to `false` to disable
|
|
12
|
+
markComment: >
|
|
13
|
+
This issue has been automatically marked as stale because it has not had
|
|
14
|
+
recent activity. It will be closed if no further activity occurs. Thank you
|
|
15
|
+
for your contributions.
|
|
16
|
+
# Comment to post when closing a stale issue. Set to `false` to disable
|
|
17
|
+
closeComment: false
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- 'master'
|
|
7
|
+
pull_request:
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
database: [ mysql, postgresql ]
|
|
13
|
+
gemfile: [ '7.0', '6.1', '6.0' ]
|
|
14
|
+
ruby: [ '2.6', '2.7', '3.0', '3.1' ]
|
|
15
|
+
exclude:
|
|
16
|
+
- ruby: '2.6'
|
|
17
|
+
gemfile: '7.0'
|
|
18
|
+
fail-fast: false
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
|
|
21
|
+
env:
|
|
22
|
+
BUNDLE_GEMFILE: gemfiles/Gemfile.rails-${{ matrix.gemfile }}.rb
|
|
23
|
+
CI: true
|
|
24
|
+
COVERALLS: true
|
|
25
|
+
DB: ${{ matrix.database }}
|
|
26
|
+
MYSQL_PASSWORD: root
|
|
27
|
+
PGHOST: localhost
|
|
28
|
+
PGPASSWORD: runner
|
|
29
|
+
PGUSER: runner
|
|
30
|
+
RAILS_ENV: test
|
|
31
|
+
|
|
32
|
+
name: ${{ matrix.ruby }} ${{ matrix.database }} rails-${{ matrix.gemfile }}
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v3
|
|
35
|
+
|
|
36
|
+
- run: sudo apt-get update && sudo apt-get install libsqlite3-dev -y
|
|
37
|
+
|
|
38
|
+
- name: "Set up MySQL using VM's server"
|
|
39
|
+
if: ${{ env.DB == 'mysql' }}
|
|
40
|
+
run: |
|
|
41
|
+
sudo apt-get install libmysqlclient-dev -y
|
|
42
|
+
sudo systemctl start mysql.service
|
|
43
|
+
|
|
44
|
+
- name: "Set up PostgreSQL using VM's server"
|
|
45
|
+
if: ${{ env.DB == 'postgresql' }}
|
|
46
|
+
run: |
|
|
47
|
+
sudo apt-get install libpq-dev -y
|
|
48
|
+
sudo systemctl start postgresql.service
|
|
49
|
+
sudo -u postgres psql -c "CREATE USER runner WITH SUPERUSER PASSWORD 'runner'"
|
|
50
|
+
sudo -u postgres createdb runner
|
|
51
|
+
|
|
52
|
+
- uses: ruby/setup-ruby@v1
|
|
53
|
+
with:
|
|
54
|
+
bundler-cache: true
|
|
55
|
+
ruby-version: ${{ matrix.ruby }}
|
|
56
|
+
|
|
57
|
+
- run: bundle exec rake db:{create,up}
|
|
58
|
+
- run: bundle exec rake test
|
data/Changelog.md
CHANGED
|
@@ -3,6 +3,47 @@
|
|
|
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
|
+
## Unreleased
|
|
7
|
+
|
|
8
|
+
## 5.5.0 (2022-11-16)
|
|
9
|
+
|
|
10
|
+
* SimpleI18n: Handle regional locales ([#965](https://github.com/norman/friendly_id/pull/965))
|
|
11
|
+
* Fix: "unknown column" exception ([#943](https://github.com/norman/friendly_id/pull/943))
|
|
12
|
+
* Add: `allow_nil: true` to the Finder ([#995](https://github.com/norman/friendly_id/pull/995) and [#997](https://github.com/norman/friendly_id/pull/997))
|
|
13
|
+
|
|
14
|
+
## 5.4.2 (2021-01-07)
|
|
15
|
+
|
|
16
|
+
* Fix: Set slug before save if needed ([#948](https://github.com/norman/friendly_id/pull/948))
|
|
17
|
+
* Revert "Make `first_by_friendly_id` case insensitive using `downcase`" ([#951](https://github.com/norman/friendly_id/pull/951))
|
|
18
|
+
|
|
19
|
+
## 5.4.1 (2020-11-06)
|
|
20
|
+
|
|
21
|
+
* Fix unexpected `:slug` error on valid, unpersisted model ([#952](https://github.com/norman/friendly_id/pull/952))
|
|
22
|
+
|
|
23
|
+
## 5.4.0 (2020-08-14)
|
|
24
|
+
|
|
25
|
+
* Fix Ruby 2.7 keyword params deprecation warning ([#939](https://github.com/norman/friendly_id/pull/939))
|
|
26
|
+
* Fix Slug Validation in `unset_slug_if_invalid` ([#938](https://github.com/norman/friendly_id/pull/938))
|
|
27
|
+
* Make `first_by_friendly_id` case insensitive using `downcase` ([#787](https://github.com/norman/friendly_id/pull/787))
|
|
28
|
+
* Use `destroy_all` rather than `delete_all` when creating historical slugs ([#924](https://github.com/norman/friendly_id/pull/924))
|
|
29
|
+
* Set required ruby version to `>= 2.1.0` ([#923](https://github.com/norman/friendly_id/pull/923))
|
|
30
|
+
* Avoid using deprecated `update_attributes` ([#922](https://github.com/norman/friendly_id/pull/922))
|
|
31
|
+
|
|
32
|
+
## 5.3.0 (2019-09-25)
|
|
33
|
+
|
|
34
|
+
* Record history when scope changes but slug does not ([#916](https://github.com/norman/friendly_id/pull/916))
|
|
35
|
+
* Add support for Rails 6 ([#897](https://github.com/norman/friendly_id/pull/897))
|
|
36
|
+
|
|
37
|
+
## 5.2.5 (2018-12-30)
|
|
38
|
+
|
|
39
|
+
* Pass all possible parameters to ActiveRecord::RecordNotFound.new when raising the exception ([#890](https://github.com/norman/friendly_id/pull/890))
|
|
40
|
+
* Use composite index for queries by sluggable ([#882](https://github.com/norman/friendly_id/pull/882))
|
|
41
|
+
* Scoped: generate new slug if scope changed ([#878](https://github.com/norman/friendly_id/pull/878))
|
|
42
|
+
* Fix History + SequentiallySlugged issues ([#877](https://github.com/norman/friendly_id/pull/877))
|
|
43
|
+
* Support scoped with STI ([#745](https://github.com/norman/friendly_id/pull/745))
|
|
44
|
+
* Fix exists? to behave the same as find for numeric slugs ([#875](https://github.com/norman/friendly_id/pull/875))
|
|
45
|
+
* Remove dirty tracking code from to_param ([#867](https://github.com/norman/friendly_id/pull/867))
|
|
46
|
+
|
|
6
47
|
## 5.2.4 (2018-04-24)
|
|
7
48
|
|
|
8
49
|
* Fix compatibility with Rails versions 4.0 -> 5.2. ([#863](https://github.com/norman/friendly_id/pull/863)).
|
data/Gemfile
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
source
|
|
1
|
+
source "https://rubygems.org"
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
|
+
gem "standard"
|
|
6
|
+
gem "rake"
|
|
7
|
+
|
|
5
8
|
group :development, :test do
|
|
6
9
|
platforms :ruby do
|
|
7
|
-
gem
|
|
10
|
+
gem "byebug"
|
|
11
|
+
gem "pry"
|
|
8
12
|
end
|
|
9
13
|
|
|
10
14
|
platforms :jruby do
|
|
11
|
-
gem
|
|
12
|
-
gem
|
|
15
|
+
gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0.beta2"
|
|
16
|
+
gem "kramdown"
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
platforms :ruby, :rbx do
|
|
16
|
-
gem
|
|
17
|
-
gem
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
platforms :rbx do
|
|
21
|
-
gem 'rubysl', '~> 2.0'
|
|
22
|
-
gem 'rubinius-developer_tools'
|
|
20
|
+
gem "sqlite3"
|
|
21
|
+
gem "redcarpet"
|
|
23
22
|
end
|
|
24
23
|
end
|
data/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
[](https://github.com/norman/friendly_id/actions)
|
|
2
2
|
[](https://codeclimate.com/github/norman/friendly_id)
|
|
3
|
-
[](https://inch-ci.org/github/norman/friendly_id)
|
|
4
4
|
|
|
5
5
|
# FriendlyId
|
|
6
6
|
|
|
7
|
-
**For the most complete, user-friendly documentation, see the [FriendlyId Guide](
|
|
7
|
+
**For the most complete, user-friendly documentation, see the [FriendlyId Guide](https://norman.github.io/friendly_id/file.Guide.html).**
|
|
8
8
|
|
|
9
9
|
FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for
|
|
10
10
|
Active Record. It lets you create pretty URLs and work with human-friendly
|
|
@@ -12,16 +12,16 @@ strings as if they were numeric ids.
|
|
|
12
12
|
|
|
13
13
|
With FriendlyId, it's easy to make your application use URLs like:
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
https://example.com/states/washington
|
|
16
16
|
|
|
17
17
|
instead of:
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
https://example.com/states/4323454
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
## Getting Help
|
|
23
23
|
|
|
24
|
-
Ask questions on [Stack Overflow](
|
|
24
|
+
Ask questions on [Stack Overflow](https://stackoverflow.com/questions/tagged/friendly-id)
|
|
25
25
|
using the "friendly-id" tag, and for bugs have a look at [the bug section](https://github.com/norman/friendly_id#bugs)
|
|
26
26
|
|
|
27
27
|
## FriendlyId Features
|
|
@@ -39,23 +39,29 @@ FriendlyId offers many advanced features, including:
|
|
|
39
39
|
Add this line to your application's Gemfile:
|
|
40
40
|
|
|
41
41
|
```ruby
|
|
42
|
-
gem 'friendly_id', '~> 5.
|
|
42
|
+
gem 'friendly_id', '~> 5.4.0'
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
Note: You MUST use 5.0.0 or greater for Rails 4.0+.
|
|
46
|
+
|
|
45
47
|
And then execute:
|
|
46
48
|
|
|
47
49
|
```shell
|
|
48
50
|
bundle install
|
|
49
51
|
```
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
Add a `slug` column to the desired table (e.g. `Users`)
|
|
54
|
+
```shell
|
|
55
|
+
rails g migration AddSlugToUsers slug:uniq
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Generate the friendly configuration file and a new migration
|
|
52
59
|
|
|
53
60
|
```shell
|
|
54
61
|
rails generate friendly_id
|
|
55
62
|
```
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
`class CreateFriendlyIdSlugs < ActiveRecord::Migration[5.1]`
|
|
64
|
+
Note: You can delete the `CreateFriendlyIdSlugs` migration if you won't use the slug history feature. ([Read more](https://norman.github.io/friendly_id/FriendlyId/History.html))
|
|
59
65
|
|
|
60
66
|
Run the migration scripts
|
|
61
67
|
|
|
@@ -91,17 +97,38 @@ User.create! name: "Joe Schmoe"
|
|
|
91
97
|
You can then access the user show page using the URL http://localhost:3000/users/joe-schmoe.
|
|
92
98
|
|
|
93
99
|
|
|
94
|
-
If you're adding FriendlyId to an existing app and need to generate slugs for
|
|
100
|
+
If you're adding FriendlyId to an existing app and need to generate slugs for
|
|
95
101
|
existing users, do this from the console, runner, or add a Rake task:
|
|
96
102
|
|
|
97
103
|
```ruby
|
|
98
104
|
User.find_each(&:save)
|
|
99
105
|
```
|
|
100
106
|
|
|
107
|
+
## Options
|
|
108
|
+
|
|
109
|
+
### `:allow_nil`
|
|
110
|
+
|
|
111
|
+
You can pass `allow_nil: true` to the `friendly.find()` method if you're want to
|
|
112
|
+
avoid raising `ActiveRecord::RecordNotFound` and accept a `nil`.
|
|
113
|
+
|
|
114
|
+
#### Example
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
MyModel.friendly.find("bad-slug") # where bad-slug is not a valid slug
|
|
118
|
+
MyModel.friendly.find(123) # where 123 is not a valid primary key ID
|
|
119
|
+
MyModel.friendly.find(nil) # maybe you have a variable/param that's potentially nil
|
|
120
|
+
#=> raise ActiveRecord::RecordNotFound
|
|
121
|
+
|
|
122
|
+
MyModel.friendly.find("bad-slug", allow_nil: true)
|
|
123
|
+
MyModel.friendly.find(123, allow_nil: true)
|
|
124
|
+
MyModel.friendly.find(nil, allow_nil: true)
|
|
125
|
+
#=> nil
|
|
126
|
+
```
|
|
127
|
+
|
|
101
128
|
## Bugs
|
|
102
129
|
|
|
103
130
|
Please report them on the [Github issue
|
|
104
|
-
tracker](
|
|
131
|
+
tracker](https://github.com/norman/friendly_id/issues) for this project.
|
|
105
132
|
|
|
106
133
|
If you have a bug to report, please include the following information:
|
|
107
134
|
|
|
@@ -113,8 +140,8 @@ If you have a bug to report, please include the following information:
|
|
|
113
140
|
If you are able to, it helps even more if you can fork FriendlyId on Github,
|
|
114
141
|
and add a test that reproduces the error you are experiencing.
|
|
115
142
|
|
|
116
|
-
For more
|
|
117
|
-
article](
|
|
143
|
+
For more inspiration on how to report bugs, please see [this
|
|
144
|
+
article](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html).
|
|
118
145
|
|
|
119
146
|
## Thanks and Credits
|
|
120
147
|
|
|
@@ -127,7 +154,7 @@ volunteers](https://github.com/norman/friendly_id/contributors).
|
|
|
127
154
|
|
|
128
155
|
## License
|
|
129
156
|
|
|
130
|
-
Copyright (c) 2008-
|
|
157
|
+
Copyright (c) 2008-2020 Norman Clarke and contributors, released under the MIT
|
|
131
158
|
license.
|
|
132
159
|
|
|
133
160
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
data/Rakefile
CHANGED
|
@@ -1,107 +1,104 @@
|
|
|
1
1
|
require "rubygems"
|
|
2
2
|
require "rake/testtask"
|
|
3
3
|
|
|
4
|
-
task :
|
|
4
|
+
task default: :test
|
|
5
5
|
|
|
6
6
|
task :load_path do
|
|
7
|
-
%w
|
|
7
|
+
%w[lib test].each do |path|
|
|
8
8
|
$LOAD_PATH.unshift(File.expand_path("../#{path}", __FILE__))
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
Rake::TestTask.new do |t|
|
|
13
13
|
t.libs << "test"
|
|
14
|
-
t.test_files = FileList[
|
|
14
|
+
t.test_files = FileList["test/*_test.rb"]
|
|
15
15
|
t.verbose = true
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
desc "Remove temporary files"
|
|
19
19
|
task :clean do
|
|
20
|
-
|
|
21
|
-
%x
|
|
20
|
+
`rm -rf *.gem doc pkg coverage`
|
|
21
|
+
%x(rm -f `find . -name '*.rbc'`)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
desc "Build the gem"
|
|
25
25
|
task :gem do
|
|
26
|
-
|
|
26
|
+
`gem build friendly_id.gemspec`
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
desc "Build YARD documentation"
|
|
30
30
|
task :yard do
|
|
31
|
-
puts
|
|
31
|
+
puts `bundle exec yard`
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
desc "Run benchmarks"
|
|
35
|
-
task :
|
|
35
|
+
task bench: :load_path do
|
|
36
36
|
require File.expand_path("../bench", __FILE__)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
desc "Run benchmarks on finders"
|
|
40
|
-
task :
|
|
40
|
+
task bench_finders: :load_path do
|
|
41
41
|
require File.expand_path("../test/benchmarks/finders", __FILE__)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
desc "Run benchmarks on ObjectUtils"
|
|
45
|
-
task :
|
|
45
|
+
task bench_object_utils: :load_path do
|
|
46
46
|
require File.expand_path("../test/benchmarks/object_utils", __FILE__)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
desc "Generate Guide.md"
|
|
50
50
|
task :guide do
|
|
51
|
-
load File.expand_path(
|
|
51
|
+
load File.expand_path("../guide.rb", __FILE__)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
namespace :test do
|
|
55
|
-
|
|
56
55
|
desc "Run each test class in a separate process"
|
|
57
56
|
task :isolated do
|
|
58
57
|
dir = File.expand_path("../test", __FILE__)
|
|
59
58
|
Dir["#{dir}/*_test.rb"].each do |test|
|
|
60
59
|
puts "Running #{test}:"
|
|
61
|
-
puts
|
|
60
|
+
puts `ruby -Ilib -Itest #{test}`
|
|
62
61
|
end
|
|
63
62
|
end
|
|
64
63
|
end
|
|
65
64
|
|
|
66
65
|
namespace :db do
|
|
67
|
-
|
|
68
66
|
desc "Create the database"
|
|
69
|
-
task :
|
|
67
|
+
task create: :load_path do
|
|
70
68
|
require "helper"
|
|
71
69
|
driver = FriendlyId::Test::Database.driver
|
|
72
70
|
config = FriendlyId::Test::Database.config[driver]
|
|
73
71
|
commands = {
|
|
74
|
-
"mysql"
|
|
75
|
-
"postgres" => "psql -c 'create database #{config[
|
|
72
|
+
"mysql" => "mysql -h #{config["host"]} -P #{config["port"]} -u #{config["username"]} --password=#{config["password"]} -e 'create database #{config["database"]};' >/dev/null",
|
|
73
|
+
"postgres" => "psql -c 'create database #{config["database"]};' -U #{config["username"]} >/dev/null"
|
|
76
74
|
}
|
|
77
|
-
|
|
75
|
+
`#{commands[driver] || true}`
|
|
78
76
|
end
|
|
79
77
|
|
|
80
78
|
desc "Drop the database"
|
|
81
|
-
task :
|
|
79
|
+
task drop: :load_path do
|
|
82
80
|
require "helper"
|
|
83
81
|
driver = FriendlyId::Test::Database.driver
|
|
84
82
|
config = FriendlyId::Test::Database.config[driver]
|
|
85
83
|
commands = {
|
|
86
|
-
"mysql"
|
|
87
|
-
"postgres" => "psql -c 'drop database #{config[
|
|
84
|
+
"mysql" => "mysql -h #{config["host"]} -P #{config["port"]} -u #{config["username"]} --password=#{config["password"]} -e 'drop database #{config["database"]};' >/dev/null",
|
|
85
|
+
"postgres" => "psql -c 'drop database #{config["database"]};' -U #{config["username"]} >/dev/null"
|
|
88
86
|
}
|
|
89
|
-
|
|
87
|
+
`#{commands[driver] || true}`
|
|
90
88
|
end
|
|
91
89
|
|
|
92
90
|
desc "Set up the database schema"
|
|
93
|
-
task :
|
|
91
|
+
task up: :load_path do
|
|
94
92
|
require "helper"
|
|
95
93
|
FriendlyId::Test::Schema.up
|
|
96
94
|
end
|
|
97
95
|
|
|
98
96
|
desc "Drop and recreate the database schema"
|
|
99
|
-
task :
|
|
100
|
-
|
|
97
|
+
task reset: [:drop, :create]
|
|
101
98
|
end
|
|
102
99
|
|
|
103
|
-
task :
|
|
100
|
+
task doc: :yard
|
|
104
101
|
|
|
105
102
|
task :docs do
|
|
106
|
-
sh %
|
|
103
|
+
sh %(git checkout gh-pages && rake doc && git checkout @{-1})
|
|
107
104
|
end
|
data/bench.rb
CHANGED
|
@@ -4,7 +4,11 @@ require "ffaker"
|
|
|
4
4
|
N = 10000
|
|
5
5
|
|
|
6
6
|
def transaction
|
|
7
|
-
ActiveRecord::Base.transaction
|
|
7
|
+
ActiveRecord::Base.transaction do
|
|
8
|
+
yield
|
|
9
|
+
|
|
10
|
+
raise ActiveRecord::Rollback
|
|
11
|
+
end
|
|
8
12
|
end
|
|
9
13
|
|
|
10
14
|
class Array
|
|
@@ -17,65 +21,64 @@ Book = Class.new ActiveRecord::Base
|
|
|
17
21
|
|
|
18
22
|
class Journalist < ActiveRecord::Base
|
|
19
23
|
extend FriendlyId
|
|
20
|
-
friendly_id :name, :
|
|
24
|
+
friendly_id :name, use: :slugged
|
|
21
25
|
end
|
|
22
26
|
|
|
23
27
|
class Manual < ActiveRecord::Base
|
|
24
28
|
extend FriendlyId
|
|
25
|
-
friendly_id :name, :
|
|
29
|
+
friendly_id :name, use: :history
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
class Restaurant < ActiveRecord::Base
|
|
29
33
|
extend FriendlyId
|
|
30
|
-
friendly_id :name, :
|
|
34
|
+
friendly_id :name, use: :finders
|
|
31
35
|
end
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
BOOKS = []
|
|
37
|
+
BOOKS = []
|
|
35
38
|
JOURNALISTS = []
|
|
36
|
-
MANUALS
|
|
39
|
+
MANUALS = []
|
|
37
40
|
RESTAURANTS = []
|
|
38
41
|
|
|
39
42
|
100.times do
|
|
40
43
|
name = FFaker::Name.name
|
|
41
|
-
BOOKS
|
|
42
|
-
JOURNALISTS << (Journalist.create! :
|
|
43
|
-
MANUALS
|
|
44
|
-
RESTAURANTS << (Restaurant.create! :
|
|
44
|
+
BOOKS << (Book.create! name: name).id
|
|
45
|
+
JOURNALISTS << (Journalist.create! name: name).friendly_id
|
|
46
|
+
MANUALS << (Manual.create! name: name).friendly_id
|
|
47
|
+
RESTAURANTS << (Restaurant.create! name: name).friendly_id
|
|
45
48
|
end
|
|
46
49
|
|
|
47
50
|
ActiveRecord::Base.connection.execute "UPDATE manuals SET slug = NULL"
|
|
48
51
|
|
|
49
52
|
Benchmark.bmbm do |x|
|
|
50
|
-
x.report
|
|
51
|
-
N.times {Book.find BOOKS.rand}
|
|
53
|
+
x.report "find (without FriendlyId)" do
|
|
54
|
+
N.times { Book.find BOOKS.rand }
|
|
52
55
|
end
|
|
53
56
|
|
|
54
|
-
x.report
|
|
55
|
-
N.times {Journalist.friendly.find JOURNALISTS.rand}
|
|
57
|
+
x.report "find (in-table slug)" do
|
|
58
|
+
N.times { Journalist.friendly.find JOURNALISTS.rand }
|
|
56
59
|
end
|
|
57
60
|
|
|
58
|
-
x.report
|
|
59
|
-
N.times {Restaurant.find RESTAURANTS.rand}
|
|
61
|
+
x.report "find (in-table slug; using finders module)" do
|
|
62
|
+
N.times { Restaurant.find RESTAURANTS.rand }
|
|
60
63
|
end
|
|
61
64
|
|
|
62
|
-
x.report
|
|
63
|
-
N.times {Manual.friendly.find MANUALS.rand}
|
|
65
|
+
x.report "find (external slug)" do
|
|
66
|
+
N.times { Manual.friendly.find MANUALS.rand }
|
|
64
67
|
end
|
|
65
68
|
|
|
66
|
-
x.report
|
|
67
|
-
N.times {transaction {Book.create :
|
|
69
|
+
x.report "insert (without FriendlyId)" do
|
|
70
|
+
N.times { transaction { Book.create name: FFaker::Name.name } }
|
|
68
71
|
end
|
|
69
72
|
|
|
70
|
-
x.report
|
|
71
|
-
N.times {transaction {Journalist.create :
|
|
73
|
+
x.report "insert (in-table-slug)" do
|
|
74
|
+
N.times { transaction { Journalist.create name: FFaker::Name.name } }
|
|
72
75
|
end
|
|
73
76
|
|
|
74
|
-
x.report
|
|
75
|
-
N.times {transaction {Restaurant.create :
|
|
77
|
+
x.report "insert (in-table-slug; using finders module)" do
|
|
78
|
+
N.times { transaction { Restaurant.create name: FFaker::Name.name } }
|
|
76
79
|
end
|
|
77
80
|
|
|
78
|
-
x.report
|
|
79
|
-
N.times {transaction {Manual.create :
|
|
81
|
+
x.report "insert (external slug)" do
|
|
82
|
+
N.times { transaction { Manual.create name: FFaker::Name.name } }
|
|
80
83
|
end
|
|
81
84
|
end
|
data/certs/parndt.pem
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIEljCCAv6gAwIBAgIBATANBgkqhkiG9w0BAQsFADBRMREwDwYDVQQDDAhydWJ5
|
|
3
|
+
Z2VtczERMA8GCgmSJomT8ixkARkWAXAxFTATBgoJkiaJk/IsZAEZFgVhcm5kdDES
|
|
4
|
+
MBAGCgmSJomT8ixkARkWAmlvMB4XDTIyMTExNTIyMjQzMFoXDTIzMTExNTIyMjQz
|
|
5
|
+
MFowUTERMA8GA1UEAwwIcnVieWdlbXMxETAPBgoJkiaJk/IsZAEZFgFwMRUwEwYK
|
|
6
|
+
CZImiZPyLGQBGRYFYXJuZHQxEjAQBgoJkiaJk/IsZAEZFgJpbzCCAaIwDQYJKoZI
|
|
7
|
+
hvcNAQEBBQADggGPADCCAYoCggGBAMPq2bIEO+BmmBeuidSySK7xlL/LWBHzyDxw
|
|
8
|
+
EMgWsHqJMDZYCZI4WoWbSTSSLrp5zPXLWN0hB23u3dxFp4RVygTTZkc8k05mteab
|
|
9
|
+
fdREGgdcP+mY8/ASQSvb1VW6IM51Srgjy1SK0S5Qf3HAiQafFvRsxRkY0SWyth24
|
|
10
|
+
ne/7HG667vHQ1+t0VFl8twupJE9S8p2zgX3eZBl2yRNm/kE5reUsOLvmS58Iri/X
|
|
11
|
+
9tnz0SGkzrKkim9OIByq7XkFLL3oaIyfbBVgOWilM5pvxj/xNuRH7EIM6aE3q0UZ
|
|
12
|
+
xo7o9u9Iz2zApDEjejByPjxWAhLuP3v3bJyinRFE1rO47lEM/s6KM/6YooxvgYIN
|
|
13
|
+
miYYFRtTj9nmKEMv6+h1mZ1/ZwqStTTRh/T90T65dcgsoqRd0JNvpNRjFrYH5cuj
|
|
14
|
+
QZWMl/FE6AADm0GXa34ZiTQx3Wx2ctqJLFak8+imPwes90nCpiYmgaZpwBI+shjU
|
|
15
|
+
AddbPDNq+EoxPMWTh0Er3w76fywOWQIDAQABo3kwdzAJBgNVHRMEAjAAMAsGA1Ud
|
|
16
|
+
DwQEAwIEsDAdBgNVHQ4EFgQUxRJaTQZmtkN8FKUWVHKc2riND18wHgYDVR0RBBcw
|
|
17
|
+
FYETcnVieWdlbXNAcC5hcm5kdC5pbzAeBgNVHRIEFzAVgRNydWJ5Z2Vtc0BwLmFy
|
|
18
|
+
bmR0LmlvMA0GCSqGSIb3DQEBCwUAA4IBgQBSRGMkZ2dvJ0LSjFz+rIt3G3AZMbKD
|
|
19
|
+
tjaaQRuC9rOkrl3Rml6h9j7cHYiM0wkTjXneFNySc8jWmM/jKnxiiUfUK9r1XL4n
|
|
20
|
+
71tz39+MD2lIpLVVEQ69MIoUseppNUTCg0mNghSDYNwISMD/hoWwbJudBi56DbhE
|
|
21
|
+
xkulLbw8qtcEE+iilIKibe+eJF4platKScsOA7d1AuilR1/S245UzeqwwyI52/xK
|
|
22
|
+
dfoP928X9Tb/48+83lWUgAgCQOd6WdfCpgQ5H6R90lc8L7OfuDR/vgcmSOTsNVgG
|
|
23
|
+
1TC3b2FISS0p0qfZsiS7BXh+ARoBKLXsV1a7WR36X0dUpajvk+zzBGrFCdbW43Gx
|
|
24
|
+
wmJzIksYnf9Ktg8Ux+FLcRBGw4qEIyWvqmS0obB1Hke68rTg0uNTFcKXsNw33XF5
|
|
25
|
+
fw1cbj95g7OPe0feGK8+afXh/L38vx/hIIOGlUEZ+HaWL2Dki/7vRGvda8dfOpG5
|
|
26
|
+
bJfaoyKbVsrK+gGKFJv860zsO8lg6BGLsUw=
|
|
27
|
+
-----END CERTIFICATE-----
|
data/friendly_id.gemspec
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
1
|
require File.expand_path("../lib/friendly_id/version", __FILE__)
|
|
3
2
|
|
|
4
3
|
Gem::Specification.new do |s|
|
|
5
|
-
s.name
|
|
6
|
-
s.version
|
|
7
|
-
s.authors
|
|
8
|
-
s.email
|
|
9
|
-
s.homepage
|
|
10
|
-
s.summary
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
13
|
-
s.
|
|
14
|
-
s.
|
|
15
|
-
s.license = 'MIT'
|
|
4
|
+
s.name = "friendly_id"
|
|
5
|
+
s.version = FriendlyId::VERSION
|
|
6
|
+
s.authors = ["Norman Clarke", "Philip Arndt"]
|
|
7
|
+
s.email = ["norman@njclarke.com", "p@arndt.io"]
|
|
8
|
+
s.homepage = "https://github.com/norman/friendly_id"
|
|
9
|
+
s.summary = "A comprehensive slugging and pretty-URL plugin."
|
|
10
|
+
s.files = `git ls-files`.split("\n")
|
|
11
|
+
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
|
12
|
+
s.require_paths = ["lib"]
|
|
13
|
+
s.license = "MIT"
|
|
16
14
|
|
|
17
|
-
s.required_ruby_version =
|
|
15
|
+
s.required_ruby_version = ">= 2.1.0"
|
|
18
16
|
|
|
19
|
-
s.add_dependency
|
|
17
|
+
s.add_dependency "activerecord", ">= 4.0.0"
|
|
20
18
|
|
|
21
|
-
s.add_development_dependency
|
|
22
|
-
s.add_development_dependency
|
|
23
|
-
s.add_development_dependency
|
|
24
|
-
s.add_development_dependency
|
|
25
|
-
s.add_development_dependency
|
|
26
|
-
s.add_development_dependency
|
|
27
|
-
s.add_development_dependency
|
|
28
|
-
s.add_development_dependency
|
|
19
|
+
s.add_development_dependency "coveralls"
|
|
20
|
+
s.add_development_dependency "railties", ">= 4.0"
|
|
21
|
+
s.add_development_dependency "minitest", "~> 5.3"
|
|
22
|
+
s.add_development_dependency "mocha", "~> 1.1"
|
|
23
|
+
s.add_development_dependency "yard"
|
|
24
|
+
s.add_development_dependency "i18n"
|
|
25
|
+
s.add_development_dependency "ffaker"
|
|
26
|
+
s.add_development_dependency "simplecov"
|
|
29
27
|
|
|
30
|
-
s.description =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
s.description = "FriendlyId is the \"Swiss Army bulldozer\" of slugging " \
|
|
29
|
+
"and permalink plugins for Active Record. It lets you create pretty URLs " \
|
|
30
|
+
"and work with human-friendly strings as if they were numeric ids."
|
|
31
|
+
|
|
32
|
+
s.cert_chain = [File.expand_path("certs/parndt.pem", __dir__)]
|
|
33
|
+
if $PROGRAM_NAME.end_with?("gem") && ARGV.include?("build") && ARGV.include?(__FILE__)
|
|
34
|
+
s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem")
|
|
35
|
+
end
|
|
35
36
|
end
|