friendly_id 5.0.4 → 5.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -11
- data/Changelog.md +13 -2
- data/Gemfile +4 -1
- data/README.md +16 -16
- data/friendly_id.gemspec +2 -2
- data/gemfiles/{Gemfile.rails-stable.rb → Gemfile.rails-4.2.rb} +3 -1
- data/lib/friendly_id.rb +1 -1
- data/lib/friendly_id/base.rb +2 -2
- data/lib/friendly_id/candidates.rb +10 -5
- data/lib/friendly_id/finders.rb +3 -0
- data/lib/friendly_id/history.rb +9 -2
- data/lib/friendly_id/initializer.rb +3 -3
- data/lib/friendly_id/scoped.rb +3 -2
- data/lib/friendly_id/slug_generator.rb +3 -7
- data/lib/friendly_id/slugged.rb +11 -11
- data/lib/friendly_id/version.rb +1 -1
- data/test/base_test.rb +2 -2
- data/test/configuration_test.rb +1 -1
- data/test/core_test.rb +1 -13
- data/test/finders_test.rb +1 -1
- data/test/helper.rb +13 -14
- data/test/history_test.rb +7 -7
- data/test/object_utils_test.rb +1 -1
- data/test/reserved_test.rb +1 -1
- data/test/scoped_test.rb +2 -33
- data/test/shared.rb +4 -2
- data/test/simple_i18n_test.rb +3 -3
- data/test/slugged_test.rb +33 -48
- data/test/sti_test.rb +3 -3
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e06bb63996e0c196fdc9b046374456806184bec
|
4
|
+
data.tar.gz: 51da9c8b121bd5a6ced25d80ca159c3eb2e993d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71d163c9f61753d7a9333885de13623458e2f41ab00aa0b26d29c772ad796678e50efb27c0026e584300453391302d5eeec6bfe2cb6e3258a4162df02791d70e
|
7
|
+
data.tar.gz: 87b4bccf78201f7c6bf16b596e4ac77f7d34e494e8ebef11e8189f5da13af61b754b8341caff647f528d0f1b5ac7a336284d9f74f47965eb8d05f7797f5c93f0
|
data/.travis.yml
CHANGED
@@ -1,27 +1,30 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
rvm:
|
3
4
|
- 2.0.0
|
4
5
|
- 2.1.0
|
5
6
|
- jruby-19mode
|
6
7
|
- rbx-2
|
8
|
+
|
7
9
|
env:
|
8
10
|
- DB=postgres
|
9
11
|
- DB=mysql
|
12
|
+
|
10
13
|
gemfile:
|
11
14
|
- gemfiles/Gemfile.rails-4.0.rb
|
12
|
-
- gemfiles/Gemfile.rails-stable.rb
|
13
15
|
- gemfiles/Gemfile.rails-4.1.rb
|
16
|
+
- gemfiles/Gemfile.rails-4.2.rb
|
17
|
+
|
18
|
+
sudo: false
|
19
|
+
|
20
|
+
# Per https://github.com/travis-ci/travis-ci/issues/2821
|
21
|
+
install: bundle install --retry=3
|
14
22
|
|
15
23
|
before_script: 'bundle exec rake db:create db:up'
|
16
|
-
|
24
|
+
|
25
|
+
script: 'COVERALLS=true bundle exec rake test'
|
26
|
+
|
17
27
|
matrix:
|
18
28
|
allow_failures:
|
19
|
-
-
|
20
|
-
|
21
|
-
env: DB=postgres
|
22
|
-
- rvm: jruby-19mode
|
23
|
-
gemfile: gemfiles/Gemfile.rails-4.1.rb
|
24
|
-
env: DB=mysql
|
25
|
-
- rvm: jruby-19mode
|
26
|
-
gemfile: gemfiles/Gemfile.rails-4.1.rb
|
27
|
-
env: DB=sqlite3
|
29
|
+
- gemfile: gemfiles/Gemfile.rails-4.2.rb
|
30
|
+
|
data/Changelog.md
CHANGED
@@ -3,14 +3,25 @@
|
|
3
3
|
We would like to think our many {file:Contributors contributors} for
|
4
4
|
suggestions, ideas and improvements to FriendlyId.
|
5
5
|
|
6
|
+
## 5.1.0 (2015-01-15)
|
7
|
+
|
8
|
+
* FriendlyId will no longer allow blank strings as slugs ([#571](https://github.com/norman/friendly_id/pull/571)).
|
9
|
+
* FriendlyId will now try to use the first non-reserved candidate as its
|
10
|
+
slug and will only mark the record invalid if all candidates ([#536](https://github.com/norman/friendly_id/issues/536)).
|
11
|
+
* Fix order dependence bug between history and scoped modules ([#588](https://github.com/norman/friendly_id/pull/588)).
|
12
|
+
* Fix "friendly" finds on Rails 4.2 ([#607](https://github.com/norman/friendly_id/issues/607)).
|
13
|
+
|
14
|
+
## 5.0.5 (2015-01-15)
|
15
|
+
|
16
|
+
* Backported bugfixes and Rails 4.2 support from 5.1.0.
|
17
|
+
|
6
18
|
## 5.0.4 (2014-05-29)
|
7
19
|
|
8
20
|
* Bug fix for call to removed `primary` method on Edge Rails. ([#557](https://github.com/norman/friendly_id/pull/557)).
|
9
|
-
* Bug
|
21
|
+
* Bug fix for unwanted slug regeneration when the slug source was changed, but not the actual generated slug ([#563](https://github.com/norman/friendly_id/pull/562)).
|
10
22
|
* Big fix to look for UUIDs only at the end of slugs ([#548](https://github.com/norman/friendly_id/pull/548)).
|
11
23
|
* Various documentation and test setup improvements.
|
12
24
|
|
13
|
-
|
14
25
|
## 5.0.3 (2013-02-14)
|
15
26
|
|
16
27
|
* Bug fix for calls to #dup with unslugged models ([#518](https://github.com/norman/friendly_id/pull/518)).
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/norman/friendly_id.
|
1
|
+
[![Build Status](https://travis-ci.org/norman/friendly_id.svg)](https://travis-ci.org/norman/friendly_id)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/norman/friendly_id.svg)](https://codeclimate.com/github/norman/friendly_id)
|
3
|
+
[![Inline docs](http://inch-ci.org/github/norman/friendly_id.svg?branch=master)](http://inch-ci.org/github/norman/friendly_id)
|
2
4
|
|
3
5
|
**GETTING HELP**
|
4
6
|
|
@@ -12,19 +14,6 @@ Please only post issues in Github issues for actual bugs.
|
|
12
14
|
I am asking people to do this because the same questions keep getting asked
|
13
15
|
over and over and over again in the issues.
|
14
16
|
|
15
|
-
**VERSION NOTE**
|
16
|
-
|
17
|
-
**Rails 4**:
|
18
|
-
|
19
|
-
The master branch of this repository contains FriendlyId 5, the current stable version.
|
20
|
-
5.x is the only version that is compatible with Rails 4.
|
21
|
-
|
22
|
-
**Rails 3**:
|
23
|
-
|
24
|
-
If you wish to use this gem with Rails 3.1 or 3.2 you must use FriendlyId 4,
|
25
|
-
which is the previous stable release. Please see the [4.0-stable
|
26
|
-
branch](https://github.com/norman/friendly_id/tree/4.0-stable).
|
27
|
-
|
28
17
|
# FriendlyId
|
29
18
|
|
30
19
|
<em>For the most complete, user-friendly documentation, see the [FriendlyId Guide](http://norman.github.io/friendly_id/file.Guide.html).</em>
|
@@ -47,6 +36,16 @@ instead of:
|
|
47
36
|
FriendlyId offers many advanced features, including: slug history and
|
48
37
|
versioning, i18n, scoped slugs, reserved words, and custom slug generators.
|
49
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
|
+
|
50
49
|
### What Changed in Version 5.0
|
51
50
|
|
52
51
|
As of version 5.0, FriendlyId uses [semantic versioning](http://semver.org/). Therefore, as you might
|
@@ -107,7 +106,7 @@ The most important changes are:
|
|
107
106
|
`should_generate_new_friendly_id?` method.
|
108
107
|
* The `friendly_id` Rails generator now generates an initializer showing you
|
109
108
|
how to do some common global configuration.
|
110
|
-
* The Globalize plugin has moved to a separate gem (currently in alpha).
|
109
|
+
* The Globalize plugin has moved to a [separate gem](https://github.com/norman/friendly_id-globalize) (currently in alpha).
|
111
110
|
* The `:reserved` module no longer includes any default reserved words.
|
112
111
|
Previously it blocked "edit" and "new" everywhere. The default word list has
|
113
112
|
been moved to `config/initializers/friendly_id.rb` and now includes many more
|
@@ -143,6 +142,7 @@ The most current docs from the master branch can always be found
|
|
143
142
|
|
144
143
|
Docs for older versions are also available:
|
145
144
|
|
145
|
+
* [5.0](http://norman.github.io/friendly_id/5.0/)
|
146
146
|
* [4.0](http://norman.github.io/friendly_id/4.0/)
|
147
147
|
* [3.3](http://norman.github.io/friendly_id/3.3/)
|
148
148
|
* [2.3](http://norman.github.io/friendly_id/2.3/)
|
@@ -162,7 +162,7 @@ cd my_app
|
|
162
162
|
```
|
163
163
|
```ruby
|
164
164
|
# Gemfile
|
165
|
-
gem 'friendly_id', '~> 5.
|
165
|
+
gem 'friendly_id', '~> 5.1.0' # Note: You MUST use 5.0.0 or greater for Rails 4.0+
|
166
166
|
```
|
167
167
|
```shell
|
168
168
|
rails generate friendly_id
|
data/friendly_id.gemspec
CHANGED
@@ -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', '
|
24
|
-
s.add_development_dependency 'mocha', '~>
|
23
|
+
s.add_development_dependency 'minitest', '~> 5.3.5'
|
24
|
+
s.add_development_dependency 'mocha', '~> 1.1.0'
|
25
25
|
s.add_development_dependency 'yard'
|
26
26
|
s.add_development_dependency 'i18n'
|
27
27
|
s.add_development_dependency 'ffaker'
|
@@ -2,11 +2,13 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec path: '../'
|
4
4
|
|
5
|
-
gem 'rails',
|
5
|
+
gem 'rails', '~> 4.2.0.rc3' do
|
6
6
|
gem 'activerecord'
|
7
7
|
gem 'railties'
|
8
8
|
end
|
9
9
|
|
10
|
+
gem 'i18n', '0.7.0.beta1'
|
11
|
+
|
10
12
|
# Database Configuration
|
11
13
|
group :development, :test do
|
12
14
|
platforms :jruby do
|
data/lib/friendly_id.rb
CHANGED
@@ -28,7 +28,7 @@ The concept of *slugs* is at the heart of FriendlyId.
|
|
28
28
|
|
29
29
|
A slug is the part of a URL which identifies a page using human-readable
|
30
30
|
keywords, rather than an opaque identifier such as a numeric id. This can make
|
31
|
-
your application more friendly both for users and search
|
31
|
+
your application more friendly both for users and search engines.
|
32
32
|
|
33
33
|
#### Finders: Slugs Act Like Numeric IDs
|
34
34
|
|
data/lib/friendly_id/base.rb
CHANGED
@@ -14,7 +14,7 @@ options:
|
|
14
14
|
end
|
15
15
|
|
16
16
|
The most important option is `:use`, which you use to tell FriendlyId which
|
17
|
-
addons it should use. See the documentation for
|
17
|
+
addons it should use. See the documentation for {FriendlyId::Base#friendly_id} for a list of all
|
18
18
|
available addons, or skim through the rest of the docs to get a high-level
|
19
19
|
overview.
|
20
20
|
|
@@ -222,7 +222,7 @@ often better and easier to use {FriendlyId::Slugged slugs}.
|
|
222
222
|
end
|
223
223
|
|
224
224
|
def primary_key_type
|
225
|
-
@primary_key_type ||=
|
225
|
+
@primary_key_type ||= columns_hash[primary_key].type
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
@@ -13,11 +13,12 @@ module FriendlyId
|
|
13
13
|
@candidates = to_candidate_array(object, array.flatten(1))
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
#
|
16
|
+
# Visits each candidate, calls it, passes it to `normalize_friendly_id` and
|
17
|
+
# yields the wanted slug candidates.
|
18
18
|
def each(*args, &block)
|
19
|
-
@candidates.
|
20
|
-
|
19
|
+
@candidates.map do |candidate|
|
20
|
+
slug = @object.normalize_friendly_id(candidate.map(&:call).join(' '))
|
21
|
+
yield slug if wanted?(slug)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -41,5 +42,9 @@ module FriendlyId
|
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
45
|
+
|
46
|
+
def wanted?(slug)
|
47
|
+
!slug.blank?
|
48
|
+
end
|
44
49
|
end
|
45
|
-
end
|
50
|
+
end
|
data/lib/friendly_id/finders.rb
CHANGED
@@ -76,6 +76,9 @@ for models that use FriendlyId with something similar to the following:
|
|
76
76
|
def self.setup(model_class)
|
77
77
|
model_class.instance_eval do
|
78
78
|
relation.class.send(:include, friendly_id_config.finder_methods)
|
79
|
+
if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2
|
80
|
+
model_class.send(:extend, friendly_id_config.finder_methods)
|
81
|
+
end
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
data/lib/friendly_id/history.rb
CHANGED
@@ -60,6 +60,9 @@ method.
|
|
60
60
|
friendly_id_config.finder_methods = FriendlyId::History::FinderMethods
|
61
61
|
if friendly_id_config.uses? :finders
|
62
62
|
relation.class.send(:include, friendly_id_config.finder_methods)
|
63
|
+
if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2
|
64
|
+
model_class.send(:extend, friendly_id_config.finder_methods)
|
65
|
+
end
|
63
66
|
end
|
64
67
|
end
|
65
68
|
end
|
@@ -87,7 +90,11 @@ method.
|
|
87
90
|
private
|
88
91
|
|
89
92
|
def first_by_friendly_id(id)
|
90
|
-
where(friendly_id_config.query_field => id).first
|
93
|
+
matching_record = where(friendly_id_config.query_field => id).first
|
94
|
+
matching_record || slug_table_record(id)
|
95
|
+
end
|
96
|
+
|
97
|
+
def slug_table_record(id)
|
91
98
|
select(quoted_table_name + '.*').joins(:slugs).where(slug_history_clause(id)).first
|
92
99
|
end
|
93
100
|
|
@@ -106,7 +113,7 @@ method.
|
|
106
113
|
return relation if new_record?
|
107
114
|
relation = relation.merge(Slug.where('sluggable_id <> ?', id))
|
108
115
|
if friendly_id_config.uses?(:scoped)
|
109
|
-
relation = relation.where(:scope
|
116
|
+
relation = relation.where(Slug.arel_table[:scope].eq(serialized_scope))
|
110
117
|
end
|
111
118
|
relation
|
112
119
|
end
|
@@ -76,9 +76,9 @@ FriendlyId.defaults do |config|
|
|
76
76
|
# }
|
77
77
|
#
|
78
78
|
# FriendlyId uses Rails's `parameterize` method to generate slugs, but for
|
79
|
-
# languages that don't use the Roman alphabet, that's not usually
|
80
|
-
# we use the Babosa library to transliterate Russian Cyrillic slugs to
|
81
|
-
# you use this, don't forget to add "babosa" to your Gemfile.
|
79
|
+
# languages that don't use the Roman alphabet, that's not usually sufficient.
|
80
|
+
# Here we use the Babosa library to transliterate Russian Cyrillic slugs to
|
81
|
+
# ASCII. If you use this, don't forget to add "babosa" to your Gemfile.
|
82
82
|
#
|
83
83
|
# config.use Module.new {
|
84
84
|
# def normalize_friendly_id(text)
|
data/lib/friendly_id/scoped.rb
CHANGED
@@ -127,7 +127,7 @@ an example of one way to set this up:
|
|
127
127
|
relation = relation.where(column => send(column))
|
128
128
|
end
|
129
129
|
primary_key_name = self.class.primary_key
|
130
|
-
relation.where.
|
130
|
+
relation.where(self.class.arel_table[primary_key_name].not_eq(send(primary_key_name)))
|
131
131
|
end
|
132
132
|
private :scope_for_slug_generator
|
133
133
|
|
@@ -163,7 +163,8 @@ an example of one way to set this up:
|
|
163
163
|
private
|
164
164
|
|
165
165
|
def reflection_foreign_key(scope)
|
166
|
-
model_class.reflections[scope].
|
166
|
+
reflection = model_class.reflections[scope] || model_class.reflections[scope.to_s]
|
167
|
+
reflection.try(:foreign_key)
|
167
168
|
end
|
168
169
|
end
|
169
170
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module FriendlyId
|
2
|
-
# The default slug generator offers functionality to check slug
|
3
|
-
#
|
2
|
+
# The default slug generator offers functionality to check slug candidates for
|
3
|
+
# availability.
|
4
4
|
class SlugGenerator
|
5
5
|
|
6
6
|
def initialize(scope)
|
@@ -11,12 +11,8 @@ module FriendlyId
|
|
11
11
|
!@scope.exists_by_friendly_id?(slug)
|
12
12
|
end
|
13
13
|
|
14
|
-
def add(slug)
|
15
|
-
slug
|
16
|
-
end
|
17
|
-
|
18
14
|
def generate(candidates)
|
19
|
-
candidates.each {|c| return
|
15
|
+
candidates.each {|c| return c if available?(c)}
|
20
16
|
nil
|
21
17
|
end
|
22
18
|
|
data/lib/friendly_id/slugged.rb
CHANGED
@@ -12,7 +12,7 @@ some text processing.
|
|
12
12
|
|
13
13
|
For example, blog applications typically use a post title to provide the basis
|
14
14
|
of a search engine friendly URL. Such identifiers typically lack uppercase
|
15
|
-
characters, use ASCII to approximate UTF-8
|
15
|
+
characters, use ASCII to approximate UTF-8 characters, and strip out other
|
16
16
|
characters which may make them aesthetically unappealing or error-prone when
|
17
17
|
used in a URL.
|
18
18
|
|
@@ -100,11 +100,11 @@ FriendlyId refers to this internally as the "base" method.
|
|
100
100
|
When you try to insert a record that would generate a duplicate friendly id,
|
101
101
|
FriendlyId will append a UUID to the generated slug to ensure uniqueness:
|
102
102
|
|
103
|
-
car = Car.create :title => "
|
104
|
-
car2 = Car.create :title => "
|
103
|
+
car = Car.create :title => "Peugeot 206"
|
104
|
+
car2 = Car.create :title => "Peugeot 206"
|
105
105
|
|
106
|
-
car.friendly_id #=> "
|
107
|
-
car2.friendly_id #=> "
|
106
|
+
car.friendly_id #=> "peugeot-206"
|
107
|
+
car2.friendly_id #=> "peugeot-206-f9f3789a-daec-4156-af1d-fab81aa16ee5"
|
108
108
|
|
109
109
|
Previous versions of FriendlyId appended a numeric sequence to make slugs
|
110
110
|
unique, but this was removed to simplify using FriendlyId in concurrent code.
|
@@ -251,9 +251,9 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
251
251
|
# Process the given value to make it suitable for use as a slug.
|
252
252
|
#
|
253
253
|
# This method is not intended to be invoked directly; FriendlyId uses it
|
254
|
-
#
|
254
|
+
# internally to process strings into slugs.
|
255
255
|
#
|
256
|
-
# However, if FriendlyId's default slug generation doesn't
|
256
|
+
# However, if FriendlyId's default slug generation doesn't suit your needs,
|
257
257
|
# you can override this method in your model class to control exactly how
|
258
258
|
# slugs are generated.
|
259
259
|
#
|
@@ -296,7 +296,7 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
296
296
|
end
|
297
297
|
|
298
298
|
def resolve_friendly_id_conflict(candidates)
|
299
|
-
candidates.first
|
299
|
+
[candidates.first, SecureRandom.uuid].compact.join(friendly_id_config.sequence_separator)
|
300
300
|
end
|
301
301
|
|
302
302
|
# Sets the slug.
|
@@ -313,7 +313,7 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
313
313
|
scope = self.class.base_class.unscoped
|
314
314
|
scope = scope.friendly unless scope.respond_to?(:exists_by_friendly_id?)
|
315
315
|
primary_key_name = self.class.primary_key
|
316
|
-
scope.where.
|
316
|
+
scope.where(self.class.base_class.arel_table[primary_key_name].not_eq(send(primary_key_name)))
|
317
317
|
end
|
318
318
|
private :scope_for_slug_generator
|
319
319
|
|
@@ -342,12 +342,12 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
342
342
|
# sequence_separator} configuration option.
|
343
343
|
# @return String The sequence separator string. Defaults to "`-`".
|
344
344
|
def sequence_separator
|
345
|
-
@sequence_separator
|
345
|
+
@sequence_separator ||= defaults[:sequence_separator]
|
346
346
|
end
|
347
347
|
|
348
348
|
# The column that will be used to store the generated slug.
|
349
349
|
def slug_column
|
350
|
-
@slug_column
|
350
|
+
@slug_column ||= defaults[:slug_column]
|
351
351
|
end
|
352
352
|
end
|
353
353
|
end
|
data/lib/friendly_id/version.rb
CHANGED
data/test/base_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
|
-
class CoreTest <
|
3
|
+
class CoreTest < Minitest::Test
|
4
4
|
include FriendlyId::Test
|
5
5
|
|
6
6
|
test "friendly_id can be added using 'extend'" do
|
@@ -69,4 +69,4 @@ class CoreTest < MiniTest::Unit::TestCase
|
|
69
69
|
FriendlyId.instance_variable_set :@defaults, nil
|
70
70
|
end
|
71
71
|
end
|
72
|
-
end
|
72
|
+
end
|
data/test/configuration_test.rb
CHANGED
data/test/core_test.rb
CHANGED
@@ -11,7 +11,7 @@ class Author < ActiveRecord::Base
|
|
11
11
|
has_many :books
|
12
12
|
end
|
13
13
|
|
14
|
-
class CoreTest <
|
14
|
+
class CoreTest < Minitest::Test
|
15
15
|
|
16
16
|
include FriendlyId::Test
|
17
17
|
include FriendlyId::Test::Shared::Core
|
@@ -33,16 +33,4 @@ class CoreTest < MiniTest::Unit::TestCase
|
|
33
33
|
test "instances should have a friendly id" do
|
34
34
|
with_instance_of(model_class) {|record| assert record.friendly_id}
|
35
35
|
end
|
36
|
-
|
37
|
-
test "instances can be marshaled when a relationship is used" do
|
38
|
-
transaction do
|
39
|
-
author = Author.create :name => 'Philip'
|
40
|
-
author.books.create :name => 'my book'
|
41
|
-
begin
|
42
|
-
assert Marshal.load(Marshal.dump(author))
|
43
|
-
rescue TypeError => e
|
44
|
-
flunk(e.to_s)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
36
|
end
|
data/test/finders_test.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -1,23 +1,22 @@
|
|
1
1
|
require "bundler/setup"
|
2
|
-
if ENV['COVERAGE']
|
3
|
-
require 'coveralls'
|
4
|
-
Coveralls.wear!
|
5
|
-
end
|
6
|
-
|
7
|
-
require "minitest/unit"
|
8
|
-
require "mocha/setup"
|
9
|
-
require "active_record"
|
10
|
-
require 'active_support/core_ext/time/conversions'
|
11
|
-
|
12
2
|
|
13
|
-
if ENV[
|
3
|
+
if ENV['COVERALLS'] || ENV['COVERAGE']
|
14
4
|
require 'simplecov'
|
5
|
+
if ENV['COVERALLS']
|
6
|
+
require 'coveralls'
|
7
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
8
|
+
end
|
15
9
|
SimpleCov.start do
|
16
|
-
add_filter
|
17
|
-
add_filter
|
10
|
+
add_filter 'test'
|
11
|
+
add_filter 'friendly_id/migration'
|
18
12
|
end
|
19
13
|
end
|
20
14
|
|
15
|
+
require 'minitest'
|
16
|
+
require "mocha/setup"
|
17
|
+
require "active_record"
|
18
|
+
require 'active_support/core_ext/time/conversions'
|
19
|
+
|
21
20
|
I18n.enforce_available_locales = false
|
22
21
|
|
23
22
|
require "friendly_id"
|
@@ -32,7 +31,7 @@ module FriendlyId
|
|
32
31
|
module Test
|
33
32
|
|
34
33
|
def self.included(base)
|
35
|
-
|
34
|
+
Minitest.autorun
|
36
35
|
end
|
37
36
|
|
38
37
|
def transaction
|
data/test/history_test.rb
CHANGED
@@ -5,7 +5,7 @@ class Manual < ActiveRecord::Base
|
|
5
5
|
friendly_id :name, :use => [:slugged, :history]
|
6
6
|
end
|
7
7
|
|
8
|
-
class HistoryTest <
|
8
|
+
class HistoryTest < Minitest::Test
|
9
9
|
|
10
10
|
include FriendlyId::Test
|
11
11
|
include FriendlyId::Test::Shared::Core
|
@@ -195,9 +195,9 @@ class HistoryTestWithFriendlyFinders < HistoryTest
|
|
195
195
|
record.save!
|
196
196
|
begin
|
197
197
|
assert model_class.find(old_friendly_id)
|
198
|
-
assert model_class.exists?(old_friendly_id), "should exist? by old id"
|
199
|
-
rescue ActiveRecord::RecordNotFound
|
200
|
-
flunk "Could not find record by old id"
|
198
|
+
assert model_class.exists?(old_friendly_id), "should exist? by old id for #{model_class.name}"
|
199
|
+
rescue ActiveRecord::RecordNotFound => e
|
200
|
+
flunk "Could not find record by old id for #{model_class.name}"
|
201
201
|
end
|
202
202
|
end
|
203
203
|
end
|
@@ -211,10 +211,10 @@ end
|
|
211
211
|
class Restaurant < ActiveRecord::Base
|
212
212
|
extend FriendlyId
|
213
213
|
belongs_to :city
|
214
|
-
friendly_id :name, :use => [:
|
214
|
+
friendly_id :name, :use => [:scoped, :history], :scope => :city
|
215
215
|
end
|
216
216
|
|
217
|
-
class ScopedHistoryTest <
|
217
|
+
class ScopedHistoryTest < Minitest::Test
|
218
218
|
include FriendlyId::Test
|
219
219
|
include FriendlyId::Test::Shared::Core
|
220
220
|
|
@@ -274,4 +274,4 @@ class ScopedHistoryTest < MiniTest::Unit::TestCase
|
|
274
274
|
assert_equal record.slug, second_record.slug
|
275
275
|
end
|
276
276
|
end
|
277
|
-
end
|
277
|
+
end
|
data/test/object_utils_test.rb
CHANGED
data/test/reserved_test.rb
CHANGED
data/test/scoped_test.rb
CHANGED
@@ -20,7 +20,7 @@ class Publisher < ActiveRecord::Base
|
|
20
20
|
has_many :novels
|
21
21
|
end
|
22
22
|
|
23
|
-
class ScopedTest <
|
23
|
+
class ScopedTest < Minitest::Test
|
24
24
|
|
25
25
|
include FriendlyId::Test
|
26
26
|
include FriendlyId::Test::Shared::Core
|
@@ -58,46 +58,14 @@ class ScopedTest < MiniTest::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
test "should not allow duplicate slugs inside scope after regeneration for persisted record" do
|
62
|
-
with_instance_of Novelist do |novelist|
|
63
|
-
novel1 = Novel.create! :name => "a", :novelist => novelist
|
64
|
-
novel2 = Novel.new :name => "a", :novelist => novelist
|
65
|
-
novel2.save!
|
66
|
-
|
67
|
-
novel2.send(:set_slug)
|
68
|
-
first_generated_friendly_id = novel2.friendly_id
|
69
|
-
novel2.send(:set_slug)
|
70
|
-
second_generated_friendly_id = novel2.friendly_id
|
71
|
-
|
72
|
-
assert novel1.friendly_id != novel2.friendly_id
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
test "should not allow duplicate slugs inside scope after regeneration for new record" do
|
77
|
-
with_instance_of Novelist do |novelist|
|
78
|
-
novel1 = Novel.create! :name => "a", :novelist => novelist
|
79
|
-
novel2 = Novel.new :name => "a", :novelist => novelist
|
80
|
-
|
81
|
-
novel2.send(:set_slug)
|
82
|
-
first_generated_friendly_id = novel2.friendly_id
|
83
|
-
novel2.send(:set_slug)
|
84
|
-
second_generated_friendly_id = novel2.friendly_id
|
85
|
-
novel2.save!
|
86
|
-
|
87
|
-
assert novel1.friendly_id != novel2.friendly_id
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
61
|
test "should apply scope with multiple columns" do
|
92
62
|
transaction do
|
93
63
|
novelist = Novelist.create! :name => "a"
|
94
64
|
publisher = Publisher.create! :name => "b"
|
95
|
-
|
96
65
|
novel1 = Novel.create! :name => "c", :novelist => novelist, :publisher => publisher
|
97
66
|
novel2 = Novel.create! :name => "c", :novelist => novelist, :publisher => Publisher.create(:name => "d")
|
98
67
|
novel3 = Novel.create! :name => "c", :novelist => Novelist.create(:name => "e"), :publisher => publisher
|
99
68
|
novel4 = Novel.create! :name => "c", :novelist => novelist, :publisher => publisher
|
100
|
-
|
101
69
|
assert_equal novel1.friendly_id, novel2.friendly_id
|
102
70
|
assert_equal novel2.friendly_id, novel3.friendly_id
|
103
71
|
assert novel3.friendly_id != novel4.friendly_id
|
@@ -112,4 +80,5 @@ class ScopedTest < MiniTest::Unit::TestCase
|
|
112
80
|
assert_equal old_id, record.friendly_id
|
113
81
|
end
|
114
82
|
end
|
83
|
+
|
115
84
|
end
|
data/test/shared.rb
CHANGED
@@ -124,8 +124,10 @@ module FriendlyId
|
|
124
124
|
with_instance_of(model_class) {|record| assert_equal record.friendly_id, record.to_param}
|
125
125
|
end
|
126
126
|
|
127
|
-
|
128
|
-
|
127
|
+
if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR < 2
|
128
|
+
test "should be findable by themselves" do
|
129
|
+
with_instance_of(model_class) {|record| assert_equal record, model_class.friendly.find(record)}
|
130
|
+
end
|
129
131
|
end
|
130
132
|
|
131
133
|
test "updating record's other values should not change the friendly_id" do
|
data/test/simple_i18n_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
|
-
class SimpleI18nTest <
|
3
|
+
class SimpleI18nTest < Minitest::Test
|
4
4
|
include FriendlyId::Test
|
5
5
|
|
6
6
|
class Journalist < ActiveRecord::Base
|
@@ -88,7 +88,7 @@ class SimpleI18nTest < MiniTest::Unit::TestCase
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
class RegressionTest <
|
91
|
+
class RegressionTest < Minitest::Test
|
92
92
|
include FriendlyId::Test
|
93
93
|
|
94
94
|
test "should not overwrite other locale's slugs on update_attributes" do
|
@@ -107,7 +107,7 @@ class SimpleI18nTest < MiniTest::Unit::TestCase
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
class ConfigurationTest <
|
110
|
+
class ConfigurationTest < Minitest::Test
|
111
111
|
test "should add locale to slug column for a non-default locale" do
|
112
112
|
I18n.with_locale :es do
|
113
113
|
assert_equal "slug_es", Journalist.friendly_id_config.slug_column
|
data/test/slugged_test.rb
CHANGED
@@ -19,7 +19,7 @@ class Novelist < ActiveRecord::Base
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
class SluggedTest <
|
22
|
+
class SluggedTest < Minitest::Test
|
23
23
|
|
24
24
|
include FriendlyId::Test
|
25
25
|
include FriendlyId::Test::Shared::Core
|
@@ -79,12 +79,12 @@ class SluggedTest < MiniTest::Unit::TestCase
|
|
79
79
|
end
|
80
80
|
|
81
81
|
test "should not update matching slug" do
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
name_changed?
|
86
|
-
end
|
82
|
+
klass = Class.new model_class do
|
83
|
+
def should_generate_new_friendly_id?
|
84
|
+
name_changed?
|
87
85
|
end
|
86
|
+
end
|
87
|
+
with_instance_of klass do |record|
|
88
88
|
old_id = record.friendly_id
|
89
89
|
record.name += " "
|
90
90
|
record.save!
|
@@ -94,7 +94,7 @@ class SluggedTest < MiniTest::Unit::TestCase
|
|
94
94
|
|
95
95
|
end
|
96
96
|
|
97
|
-
class SlugGeneratorTest <
|
97
|
+
class SlugGeneratorTest < Minitest::Test
|
98
98
|
|
99
99
|
include FriendlyId::Test
|
100
100
|
|
@@ -156,38 +156,9 @@ class SlugGeneratorTest < MiniTest::Unit::TestCase
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
test "should not allow duplicate slugs after regeneration for persisted record" do
|
160
|
-
transaction do
|
161
|
-
model1 = model_class.create! :name => "a"
|
162
|
-
model2 = model_class.new :name => "a"
|
163
|
-
model2.save!
|
164
|
-
|
165
|
-
model2.send(:set_slug)
|
166
|
-
first_generated_friendly_id = model2.friendly_id
|
167
|
-
model2.send(:set_slug)
|
168
|
-
second_generated_friendly_id = model2.friendly_id
|
169
|
-
|
170
|
-
assert model1.friendly_id != model2.friendly_id
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
test "should not allow duplicate slugs after regeneration for new record" do
|
175
|
-
transaction do
|
176
|
-
model1 = model_class.create! :name => "a"
|
177
|
-
model2 = model_class.new :name => "a"
|
178
|
-
|
179
|
-
model2.send(:set_slug)
|
180
|
-
first_generated_friendly_id = model2.friendly_id
|
181
|
-
model2.send(:set_slug)
|
182
|
-
second_generated_friendly_id = model2.friendly_id
|
183
|
-
|
184
|
-
assert model1.friendly_id != model2.friendly_id
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
159
|
end
|
189
160
|
|
190
|
-
class SlugSeparatorTest <
|
161
|
+
class SlugSeparatorTest < Minitest::Test
|
191
162
|
|
192
163
|
include FriendlyId::Test
|
193
164
|
|
@@ -230,9 +201,16 @@ class SlugSeparatorTest < MiniTest::Unit::TestCase
|
|
230
201
|
assert_match(/\Apeugeot-206-([a-z0-9]+\-){4}[a-z0-9]+\z/, record2.slug)
|
231
202
|
end
|
232
203
|
end
|
204
|
+
|
205
|
+
test "should sequence blank slugs without a separator" do
|
206
|
+
with_instance_of model_class, :name => "" do |record|
|
207
|
+
assert_match(/\A([a-z0-9]+\-){4}[a-z0-9]+\z/, record.slug)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
233
211
|
end
|
234
212
|
|
235
|
-
class DefaultScopeTest <
|
213
|
+
class DefaultScopeTest < Minitest::Test
|
236
214
|
|
237
215
|
include FriendlyId::Test
|
238
216
|
|
@@ -254,9 +232,11 @@ class DefaultScopeTest < MiniTest::Unit::TestCase
|
|
254
232
|
assert Journalist.create :name => "a", :active => true
|
255
233
|
end
|
256
234
|
end
|
235
|
+
|
257
236
|
end
|
258
237
|
|
259
|
-
class UuidAsPrimaryKeyFindTest <
|
238
|
+
class UuidAsPrimaryKeyFindTest < Minitest::Test
|
239
|
+
|
260
240
|
include FriendlyId::Test
|
261
241
|
|
262
242
|
class MenuItem < ActiveRecord::Base
|
@@ -284,9 +264,8 @@ class UuidAsPrimaryKeyFindTest < MiniTest::Unit::TestCase
|
|
284
264
|
end
|
285
265
|
|
286
266
|
test "should have a uuid_key as a primary key" do
|
287
|
-
assert_equal model_class.primary_key
|
288
|
-
assert_equal
|
289
|
-
assert_equal model_class.primary_key_type, :uuid
|
267
|
+
assert_equal "uuid_key", model_class.primary_key
|
268
|
+
assert_equal :uuid, model_class.primary_key_type
|
290
269
|
end
|
291
270
|
|
292
271
|
test "should be findable by the UUID primary key" do
|
@@ -302,9 +281,11 @@ class UuidAsPrimaryKeyFindTest < MiniTest::Unit::TestCase
|
|
302
281
|
end
|
303
282
|
end
|
304
283
|
end
|
284
|
+
|
305
285
|
end
|
306
286
|
|
307
|
-
class UnderscoreAsSequenceSeparatorRegressionTest <
|
287
|
+
class UnderscoreAsSequenceSeparatorRegressionTest < Minitest::Test
|
288
|
+
|
308
289
|
include FriendlyId::Test
|
309
290
|
|
310
291
|
class Manual < ActiveRecord::Base
|
@@ -314,10 +295,12 @@ class UnderscoreAsSequenceSeparatorRegressionTest < MiniTest::Unit::TestCase
|
|
314
295
|
|
315
296
|
test "should not create duplicate slugs" do
|
316
297
|
3.times do
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
298
|
+
transaction do
|
299
|
+
begin
|
300
|
+
assert Manual.create! :name => "foo"
|
301
|
+
rescue
|
302
|
+
flunk "Tried to insert duplicate slug"
|
303
|
+
end
|
321
304
|
end
|
322
305
|
end
|
323
306
|
end
|
@@ -325,7 +308,8 @@ class UnderscoreAsSequenceSeparatorRegressionTest < MiniTest::Unit::TestCase
|
|
325
308
|
end
|
326
309
|
|
327
310
|
# https://github.com/norman/friendly_id/issues/148
|
328
|
-
class FailedValidationAfterUpdateRegressionTest <
|
311
|
+
class FailedValidationAfterUpdateRegressionTest < Minitest::Test
|
312
|
+
|
329
313
|
include FriendlyId::Test
|
330
314
|
|
331
315
|
class Journalist < ActiveRecord::Base
|
@@ -346,4 +330,5 @@ class FailedValidationAfterUpdateRegressionTest < MiniTest::Unit::TestCase
|
|
346
330
|
assert_equal "joseph-pulitzer", journalist.to_param
|
347
331
|
end
|
348
332
|
end
|
333
|
+
|
349
334
|
end
|
data/test/sti_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
|
-
class StiTest <
|
3
|
+
class StiTest < Minitest::Test
|
4
4
|
|
5
5
|
include FriendlyId::Test
|
6
6
|
include FriendlyId::Test::Shared::Core
|
@@ -76,7 +76,7 @@ class StiTestWithHistory < StiTest
|
|
76
76
|
end
|
77
77
|
|
78
78
|
|
79
|
-
class StiTestWithFinders <
|
79
|
+
class StiTestWithFinders < Minitest::Test
|
80
80
|
|
81
81
|
include FriendlyId::Test
|
82
82
|
|
@@ -110,7 +110,7 @@ class StiTestWithFinders < MiniTest::Unit::TestCase
|
|
110
110
|
|
111
111
|
end
|
112
112
|
|
113
|
-
class StiTestSubClass <
|
113
|
+
class StiTestSubClass < Minitest::Test
|
114
114
|
|
115
115
|
include FriendlyId::Test
|
116
116
|
|
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.0.
|
4
|
+
version: 5.0.5
|
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:
|
12
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -57,30 +57,30 @@ dependencies:
|
|
57
57
|
name: minitest
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: 5.3.5
|
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:
|
69
|
+
version: 5.3.5
|
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:
|
76
|
+
version: 1.1.0
|
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:
|
83
|
+
version: 1.1.0
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: yard
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,7 +162,7 @@ files:
|
|
162
162
|
- friendly_id.gemspec
|
163
163
|
- gemfiles/Gemfile.rails-4.0.rb
|
164
164
|
- gemfiles/Gemfile.rails-4.1.rb
|
165
|
-
- gemfiles/Gemfile.rails-
|
165
|
+
- gemfiles/Gemfile.rails-4.2.rb
|
166
166
|
- guide.rb
|
167
167
|
- lib/friendly_id.rb
|
168
168
|
- lib/friendly_id/.gitattributes
|
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
219
|
version: '0'
|
220
220
|
requirements: []
|
221
221
|
rubyforge_project: friendly_id
|
222
|
-
rubygems_version: 2.
|
222
|
+
rubygems_version: 2.4.4
|
223
223
|
signing_key:
|
224
224
|
specification_version: 4
|
225
225
|
summary: A comprehensive slugging and pretty-URL plugin.
|