friendly_id 5.0.3 → 5.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae540f2127bb8f4e872640deb40fe582eedad06a
4
- data.tar.gz: 8d9e0ddb7339a440bd8000240a083b5586dee6a8
3
+ metadata.gz: 6650a7d112a806cb566708865ade666184dab77a
4
+ data.tar.gz: 2cde3e354e65e588d566a02f7e61d2b7e5e77657
5
5
  SHA512:
6
- metadata.gz: dcbcea5a8df1f5919c72ac9775ad619953fc776a7191c5e163d04c3361d9338fda12e37a7b50104345ef8583c3e8ac589b563231aa99e97cf52ed5305550fd2d
7
- data.tar.gz: 2f48d2758e511c32ad5de5187c28509799cd2a46180d6d9b69ee6e190a5d8449b076e9f8cf7ef1159a69b6fc572f650bcb907087303ac2396b483418b2fe71d1
6
+ metadata.gz: 38805122e7a3cef575c89dab8945589815c80d871ec01f6f2932fb7542a9240b00cdb3506d8cc1edbe5f42aa65d96c66cf5c3909dd9f4eefd5dfa03745f846c9
7
+ data.tar.gz: fc87f81b4c941571d34c961efa2fa6c81fbb02c29befa9a7b615ff7a3c392884f8dea699be2774c231449aeb2c982a38aea47bc7504b70e5f34b2847d0a491ae
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ rvm:
3
3
  - 2.0.0
4
4
  - 2.1.0
5
5
  - jruby-19mode
6
- - rbx
6
+ - rbx-2
7
7
  env:
8
8
  - DB=postgres
9
9
  - DB=mysql
data/Changelog.md CHANGED
@@ -3,14 +3,27 @@
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.0.4 (2014-05-29)
7
+
8
+ * Bug fix for call to removed `primary` method on Edge Rails. ([#557](https://github.com/norman/friendly_id/pull/557)).
9
+ * Bug for for unwanted slug regeneration when the slug source was not changed, but not the actual generated slug ([#563](https://github.com/norman/friendly_id/pull/562)).
10
+ * Big fix to look for UUIDs only at the end of slugs ([#548](https://github.com/norman/friendly_id/pull/548)).
11
+ * Various documentation and test setup improvements.
12
+
13
+
14
+ ## 5.0.3 (2013-02-14)
15
+
16
+ * Bug fix for calls to #dup with unslugged models ([#518](https://github.com/norman/friendly_id/pull/518)).
17
+ * Bug fixes for STI ([#516](https://github.com/norman/friendly_id/pull/516)).
18
+ * Bug fix for slug regeneration (both scoped and unscoped) ([#513](https://github.com/norman/friendly_id/pull/513)).
19
+ * Bug fix for finds with models that use the :history module ([#509](https://github.com/norman/friendly_id/pull/509)).
20
+
6
21
  ## 5.0.2 (2013-12-10)
7
22
 
8
23
  * Query performance improvements ([#497](https://github.com/norman/friendly_id/pull/497)).
9
24
  * Documentation improvements (thanks [John Bachir](https://github.com/jjb)).
10
25
  * Minor refactoring of internals (thanks [Gagan Ahwad](https://github.com/gaganawhad)).
11
26
  * Set slug to `nil` on call to `dup` to ensure slug is generated ([#483](https://github.com/norman/friendly_id/pull/483)).
12
- * Bug fixes for STI ([#516](https://github.com/norman/friendly_id/pull/516)).
13
- * Bug fix for finds with models that use the :history module ([#509](https://github.com/norman/friendly_id/pull/509)).
14
27
 
15
28
  ## 5.0.1 (2013-10-27)
16
29
 
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2010 Norman Clarke, Adrian Mugnolo and Emilio Tagua.
1
+ Copyright (c) 2008-2014 Norman Clarke, Adrian Mugnolo and Emilio Tagua.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -145,6 +145,7 @@ Docs for older versions are also available:
145
145
 
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
+ * [2.3](http://norman.github.io/friendly_id/2.3/)
148
149
 
149
150
  The best place to start is with the
150
151
  [Guide](http://norman.github.io/friendly_id/file.Guide.html),
@@ -165,13 +166,7 @@ gem 'friendly_id', '~> 5.0.0' # Note: You MUST use 5.0.0 or greater for Rails 4.
165
166
  ```
166
167
  ```shell
167
168
  rails generate friendly_id
168
- rails generate scaffold user name:string slug:string
169
- ```
170
- ```ruby
171
- # edit db/migrate/*_create_users.rb
172
- add_index :users, :slug, unique: true
173
- ```
174
- ```shell
169
+ rails generate scaffold user name:string slug:string:uniq
175
170
  rake db:migrate
176
171
  ```
177
172
  ```ruby
@@ -233,7 +228,7 @@ volunteers](https://github.com/norman/friendly_id/contributors).
233
228
 
234
229
  ## License
235
230
 
236
- Copyright (c) 2008-2013 Norman Clarke and contributors, released under the MIT
231
+ Copyright (c) 2008-2014 Norman Clarke and contributors, released under the MIT
237
232
  license.
238
233
 
239
234
  Permission is hereby granted, free of charge, to any person obtaining a copy of
data/friendly_id.gemspec CHANGED
@@ -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.0'
22
+ s.add_development_dependency 'railties', '~> 4.0'
23
23
  s.add_development_dependency 'minitest', '>= 4.4.0'
24
24
  s.add_development_dependency 'mocha', '~> 0.13.3'
25
25
  s.add_development_dependency 'yard'
@@ -2,8 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '../'
4
4
 
5
- gem 'activerecord', '~> 4.1.0.beta1'
6
- gem 'railties', '~> 4.1.0.beta1'
5
+ gem 'activerecord', '~> 4.1.0'
6
+ gem 'railties', '~> 4.1.0'
7
7
 
8
8
  # Database Configuration
9
9
  group :development, :test do
@@ -26,4 +26,4 @@ group :development, :test do
26
26
  gem 'rubinius-developer_tools'
27
27
  gem 'json'
28
28
  end
29
- end
29
+ end
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '../'
4
4
 
5
- gem 'rails', github: 'rails/rails', branch: '4-0-stable' do
5
+ gem 'rails', github: 'rails/rails', branch: '4-1-stable' do
6
6
  gem 'activerecord'
7
7
  gem 'railties'
8
8
  end
@@ -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 ||= columns.find(&:primary).type
225
+ @primary_key_type ||= columns.find { |c| c.name == primary_key}.type
226
226
  end
227
227
  end
228
228
 
@@ -47,7 +47,7 @@ module FriendlyId
47
47
  when :integer
48
48
  Integer(id, 10) rescue false
49
49
  when :uuid
50
- id.match /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
50
+ id.match /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/
51
51
  else
52
52
  true
53
53
  end
@@ -126,11 +126,8 @@ an example of one way to set this up:
126
126
  friendly_id_config.scope_columns.each do |column|
127
127
  relation = relation.where(column => send(column))
128
128
  end
129
- if changed.include?(friendly_id_config.slug_column)
130
- primary_key_name = self.class.primary_key
131
- relation = relation.where.not(primary_key_name => send(primary_key_name))
132
- end
133
- relation
129
+ primary_key_name = self.class.primary_key
130
+ relation.where.not(primary_key_name => send(primary_key_name))
134
131
  end
135
132
  private :scope_for_slug_generator
136
133
 
@@ -186,6 +186,18 @@ control exactly when new friendly ids are set:
186
186
  end
187
187
  end
188
188
 
189
+ If you want to extend the default behavior but, adding your own conditions,
190
+ don't forget to invoke `super` from your implementation:
191
+
192
+ class Category < ActiveRecord::Base
193
+ extend FriendlyId
194
+ friendly_id :name, :use => :slugged
195
+
196
+ def should_generate_new_friendly_id?
197
+ name_changed? || super
198
+ end
199
+ end
200
+
189
201
  #### Locale-specific Transliterations
190
202
 
191
203
  Active Support's `parameterize` uses
@@ -300,12 +312,8 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
300
312
  def scope_for_slug_generator
301
313
  scope = self.class.base_class.unscoped
302
314
  scope = scope.friendly unless scope.respond_to?(:exists_by_friendly_id?)
303
-
304
- if changed.include?(friendly_id_config.slug_column)
305
- primary_key_name = self.class.primary_key
306
- scope = scope.where.not(primary_key_name => send(primary_key_name))
307
- end
308
- scope
315
+ primary_key_name = self.class.primary_key
316
+ scope.where.not(primary_key_name => send(primary_key_name))
309
317
  end
310
318
  private :scope_for_slug_generator
311
319
 
@@ -1,3 +1,3 @@
1
1
  module FriendlyId
2
- VERSION = "5.0.3"
2
+ VERSION = "5.0.4"
3
3
  end
data/test/helper.rb CHANGED
@@ -18,6 +18,8 @@ if ENV["COVERAGE"]
18
18
  end
19
19
  end
20
20
 
21
+ I18n.enforce_available_locales = false
22
+
21
23
  require "friendly_id"
22
24
 
23
25
  # If you want to see the ActiveRecord log, invoke the tests using `rake test LOG=true`
data/test/schema.rb CHANGED
@@ -23,10 +23,10 @@ module FriendlyId
23
23
  end
24
24
  end
25
25
 
26
- tables_with_string_primary_key.each do |table_name|
27
- create_table table_name, primary_key: :string_key, id: false do |t|
26
+ tables_with_uuid_primary_key.each do |table_name|
27
+ create_table table_name, primary_key: :uuid_key, id: false do |t|
28
28
  t.string :name
29
- t.string :string_key, null: false
29
+ t.string :uuid_key, null: false
30
30
  t.string :slug
31
31
  end
32
32
  add_index table_name, :slug, unique: true
@@ -73,7 +73,7 @@ module FriendlyId
73
73
  %w[journalists articles novelists novels manuals]
74
74
  end
75
75
 
76
- def tables_with_string_primary_key
76
+ def tables_with_uuid_primary_key
77
77
  ["menu_items"]
78
78
  end
79
79
 
data/test/slugged_test.rb CHANGED
@@ -77,6 +77,21 @@ class SluggedTest < MiniTest::Unit::TestCase
77
77
  assert_equal old_id, record.friendly_id
78
78
  end
79
79
  end
80
+
81
+ test "should not update matching slug" do
82
+ with_instance_of(model_class) do |record|
83
+ class << record
84
+ def should_generate_new_friendly_id?
85
+ name_changed?
86
+ end
87
+ end
88
+ old_id = record.friendly_id
89
+ record.name += " "
90
+ record.save!
91
+ assert_equal old_id, record.friendly_id
92
+ end
93
+ end
94
+
80
95
  end
81
96
 
82
97
  class SlugGeneratorTest < MiniTest::Unit::TestCase
@@ -119,10 +134,10 @@ class SlugGeneratorTest < MiniTest::Unit::TestCase
119
134
 
120
135
  test "should correctly sequence slugs that end with numbers" do
121
136
  transaction do
122
- record1 = model_class.create! :name => "Peugeuot 206"
123
- assert_equal "peugeuot-206", record1.slug
124
- record2 = model_class.create! :name => "Peugeuot 206"
125
- assert_match(/\Apeugeuot-206-([a-z0-9]+\-){4}[a-z0-9]+\z/, record2.slug)
137
+ record1 = model_class.create! :name => "Peugeot 206"
138
+ assert_equal "peugeot-206", record1.slug
139
+ record2 = model_class.create! :name => "Peugeot 206"
140
+ assert_match(/\Apeugeot-206-([a-z0-9]+\-){4}[a-z0-9]+\z/, record2.slug)
126
141
  end
127
142
  end
128
143
 
@@ -209,10 +224,10 @@ class SlugSeparatorTest < MiniTest::Unit::TestCase
209
224
  end
210
225
  end
211
226
  transaction do
212
- record1 = model_class.create! :name => "Peugeuot 206"
213
- assert_equal "peugeuot-206", record1.slug
214
- record2 = model_class.create! :name => "Peugeuot 206"
215
- assert_match(/\Apeugeuot-206-([a-z0-9]+\-){4}[a-z0-9]+\z/, record2.slug)
227
+ record1 = model_class.create! :name => "Peugeot 206"
228
+ assert_equal "peugeot-206", record1.slug
229
+ record2 = model_class.create! :name => "Peugeot 206"
230
+ assert_match(/\Apeugeot-206-([a-z0-9]+\-){4}[a-z0-9]+\z/, record2.slug)
216
231
  end
217
232
  end
218
233
  end
@@ -241,7 +256,7 @@ class DefaultScopeTest < MiniTest::Unit::TestCase
241
256
  end
242
257
  end
243
258
 
244
- class StringAsPrimaryKeyFindTest < MiniTest::Unit::TestCase
259
+ class UuidAsPrimaryKeyFindTest < MiniTest::Unit::TestCase
245
260
  include FriendlyId::Test
246
261
 
247
262
  class MenuItem < ActiveRecord::Base
@@ -250,12 +265,17 @@ class StringAsPrimaryKeyFindTest < MiniTest::Unit::TestCase
250
265
  before_create :init_primary_key
251
266
 
252
267
  def self.primary_key
253
- "string_key"
268
+ "uuid_key"
269
+ end
270
+
271
+ # Overwrite the method added by FriendlyId
272
+ def self.primary_key_type
273
+ :uuid
254
274
  end
255
275
 
256
276
  private
257
277
  def init_primary_key
258
- self.string_key = SecureRandom.uuid
278
+ self.uuid_key = SecureRandom.uuid
259
279
  end
260
280
  end
261
281
 
@@ -263,16 +283,25 @@ class StringAsPrimaryKeyFindTest < MiniTest::Unit::TestCase
263
283
  MenuItem
264
284
  end
265
285
 
266
- test "should have a string as a primary key" do
267
- assert_equal model_class.primary_key, "string_key"
268
- assert_equal model_class.columns.find(&:primary).name, "string_key"
286
+ test "should have a uuid_key as a primary key" do
287
+ assert_equal model_class.primary_key, "uuid_key"
288
+ assert_equal model_class.columns.find { |c| c.name == model_class.primary_key}.name, "uuid_key"
289
+ assert_equal model_class.primary_key_type, :uuid
269
290
  end
270
291
 
271
- test "should be findable by the string primary key" do
292
+ test "should be findable by the UUID primary key" do
272
293
  with_instance_of(model_class) do |record|
273
294
  assert model_class.friendly.find record.id
274
295
  end
275
296
  end
297
+
298
+ test "should handle a string that simply contains a UUID correctly" do
299
+ with_instance_of(model_class) do |record|
300
+ assert_raises(ActiveRecord::RecordNotFound) do
301
+ model_class.friendly.find "test-#{SecureRandom.uuid}"
302
+ end
303
+ end
304
+ end
276
305
  end
277
306
 
278
307
  class UnderscoreAsSequenceSeparatorRegressionTest < MiniTest::Unit::TestCase
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.3
4
+ version: 5.0.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: 2014-02-14 00:00:00.000000000 Z
12
+ date: 2014-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 4.0.0
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
- version: 4.0.0
55
+ version: '4.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: minitest
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -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.2.0
222
+ rubygems_version: 2.2.2
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: A comprehensive slugging and pretty-URL plugin.