friendly_id 2.1.3 → 2.1.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.
- data.tar.gz.sig +1 -2
- data/History.txt +9 -2
- data/README.rdoc +4 -4
- data/Rakefile +7 -9
- data/friendly_id.gemspec +4 -3
- data/generators/friendly_id/templates/create_slugs.rb +2 -2
- data/generators/friendly_id_20_upgrade/friendly_id_20_upgrade_generator.rb +1 -0
- data/generators/friendly_id_20_upgrade/templates/upgrade_friendly_id_to_20.rb +1 -1
- data/init.rb +2 -0
- data/lib/friendly_id.rb +2 -0
- data/lib/friendly_id/helpers.rb +2 -0
- data/lib/friendly_id/non_sluggable_class_methods.rb +2 -0
- data/lib/friendly_id/non_sluggable_instance_methods.rb +2 -0
- data/lib/friendly_id/slug.rb +1 -11
- data/lib/friendly_id/sluggable_class_methods.rb +5 -3
- data/lib/friendly_id/sluggable_instance_methods.rb +2 -0
- data/lib/friendly_id/version.rb +4 -2
- data/lib/tasks/friendly_id.rake +2 -0
- data/test/models/post.rb +3 -0
- data/test/non_slugged_test.rb +2 -0
- data/test/schema.rb +3 -0
- data/test/scoped_model_test.rb +2 -0
- data/test/slugged_model_test.rb +14 -3
- data/test/test_helper.rb +2 -12
- metadata +3 -3
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
��=x.��a�]���V�s�}OA��qE���b�E=3y���O�{(B�^iW�m�
|
|
1
|
+
o���Z����u����i(v�U�>��=PA)Fj�1��b?9�W^e��B��#+�6�j<g�.�B��.S�*��E�iR�s����#���"�x`����������gV�Lyx�H�w!T������Xz�A���qЏ��d�<=R�2圲@�<���X#�I��p�!�QĪ�nK������� �>q���Y���#M�����\������5C<E��4�Bpd�!?����g�#/����6s�#$>ן�
|
data/History.txt
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
== 2.1.4 2009-09-01
|
|
2
|
+
|
|
3
|
+
* 1 minor enhancement:
|
|
4
|
+
* Fixed upgrade generator not installing rake tasks (Harry Love)
|
|
5
|
+
* Fixed handling of very large id's (Nathan Phelps)
|
|
6
|
+
* Fixed long index name on migration (Ron Ingram)
|
|
7
|
+
|
|
1
8
|
== 2.1.3 2009-06-03
|
|
2
9
|
|
|
3
10
|
* 1 minor enhancement:
|
|
@@ -12,9 +19,9 @@
|
|
|
12
19
|
== 2.1.1 2009-03-25
|
|
13
20
|
|
|
14
21
|
* 2 minor enhancements:
|
|
15
|
-
* Fixed bug with find_some; if a record has old slugs, find_some will no longer return
|
|
22
|
+
* Fixed bug with find_some; if a record has old slugs, find_some will no longer return
|
|
16
23
|
multiple copies of that record when finding by numerical ID. (Steve Luscher)
|
|
17
|
-
* Fixed bug with find_some: you can now find_some with an array of numerical IDs without
|
|
24
|
+
* Fixed bug with find_some: you can now find_some with an array of numerical IDs without
|
|
18
25
|
an error being thrown. (Steve Luscher)
|
|
19
26
|
|
|
20
27
|
== 2.1.0 2009-03-25
|
data/README.rdoc
CHANGED
|
@@ -270,16 +270,16 @@ an older version of FriendlyId. Here's how to set it up.
|
|
|
270
270
|
4) If you are using slugs, you can use a Rake task to generate slugs for your
|
|
271
271
|
existing records:
|
|
272
272
|
|
|
273
|
-
friendly_id:make_slugs MODEL=MyModelName
|
|
273
|
+
rake friendly_id:make_slugs MODEL=MyModelName
|
|
274
274
|
|
|
275
275
|
If you eventually want to expire old slugs every so often, or perhaps every
|
|
276
276
|
day via cron, you can do:
|
|
277
277
|
|
|
278
|
-
rake
|
|
278
|
+
rake friendly_id:remove_old_slugs
|
|
279
279
|
|
|
280
280
|
The default is to remove dead slugs older than 45 days, but is configurable:
|
|
281
281
|
|
|
282
|
-
rake
|
|
282
|
+
rake friendly_id:remove_old_slugs MODEL=MyModelName DAYS=60
|
|
283
283
|
|
|
284
284
|
== Installing an older version
|
|
285
285
|
|
|
@@ -321,7 +321,7 @@ Add this to the bottom of environment.rb:
|
|
|
321
321
|
|
|
322
322
|
==== Generate the upgrade migration and run it
|
|
323
323
|
|
|
324
|
-
./script
|
|
324
|
+
./script/generate friendly_id_20_upgrade
|
|
325
325
|
rake db:migrate
|
|
326
326
|
|
|
327
327
|
== Hacking FriendlyId:
|
data/Rakefile
CHANGED
|
@@ -31,15 +31,13 @@ def run_coverage(files)
|
|
|
31
31
|
return
|
|
32
32
|
end
|
|
33
33
|
files = files.join(" ")
|
|
34
|
-
if
|
|
35
|
-
|
|
36
|
-
else
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
rcov = "
|
|
40
|
-
|
|
41
|
-
puts cmd
|
|
42
|
-
sh cmd
|
|
34
|
+
# if RUBY_PLATFORM =~ /darwin/
|
|
35
|
+
# exclude = '--exclude "gems/"'
|
|
36
|
+
# else
|
|
37
|
+
# exclude = '--exclude "rubygems"'
|
|
38
|
+
# end
|
|
39
|
+
rcov = ENV["RCOV"] ? ENV["RCOV"] : "rcov"
|
|
40
|
+
sh "#{rcov} -Ilib:test --sort coverage --text-report #{files}"
|
|
43
41
|
end
|
|
44
42
|
|
|
45
43
|
desc 'Publish RDoc to RubyForge.'
|
data/friendly_id.gemspec
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{friendly_id}
|
|
5
|
-
s.version = "2.1.
|
|
5
|
+
s.version = "2.1.4"
|
|
6
|
+
|
|
6
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
7
8
|
s.authors = ["Norman Clarke", "Adrian Mugnolo", "Emilio Tagua"]
|
|
8
|
-
s.date = %q{2009-
|
|
9
|
+
s.date = %q{2009-09-01}
|
|
9
10
|
s.description = %q{A comprehensive slugging and pretty-URL plugin for ActiveRecord.}
|
|
10
11
|
s.email = ["norman@rubysouth.com", "adrian@rubysouth.com", "miloops@gmail.com"]
|
|
11
12
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
|
@@ -14,7 +15,7 @@ Gem::Specification.new do |s|
|
|
|
14
15
|
s.rdoc_options = ["--main", "README.rdoc"]
|
|
15
16
|
s.require_paths = ["lib"]
|
|
16
17
|
s.rubyforge_project = %q{friendly-id}
|
|
17
|
-
s.rubygems_version = %q{1.3.
|
|
18
|
+
s.rubygems_version = %q{1.3.4}
|
|
18
19
|
s.summary = %q{A comprehensive slugging and pretty-URL plugin for ActiveRecord.}
|
|
19
20
|
s.test_files = ["test/custom_slug_normalizer_test.rb", "test/non_slugged_test.rb", "test/scoped_model_test.rb", "test/slug_test.rb", "test/slugged_model_test.rb", "test/sti_test.rb"]
|
|
20
21
|
|
|
@@ -8,11 +8,11 @@ class CreateSlugs < ActiveRecord::Migration
|
|
|
8
8
|
t.string :scope, :limit => 40
|
|
9
9
|
t.datetime :created_at
|
|
10
10
|
end
|
|
11
|
-
add_index :slugs, [:name, :sluggable_type, :scope, :sequence], :unique => true
|
|
11
|
+
add_index :slugs, [:name, :sluggable_type, :scope, :sequence], :name => "index_slugs_on_n_s_s_and_s", :unique => true
|
|
12
12
|
add_index :slugs, :sluggable_id
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def self.down
|
|
16
16
|
drop_table :slugs
|
|
17
17
|
end
|
|
18
|
-
end
|
|
18
|
+
end
|
|
@@ -5,6 +5,7 @@ class FriendlyId20UpgradeGenerator < Rails::Generator::Base
|
|
|
5
5
|
m.migration_template(
|
|
6
6
|
'upgrade_friendly_id_to_20.rb', 'db/migrate', :migration_file_name => 'upgrade_friendly_id_to_20'
|
|
7
7
|
)
|
|
8
|
+
m.file "/../../../lib/tasks/friendly_id.rake", "lib/tasks/friendly_id.rake"
|
|
8
9
|
end
|
|
9
10
|
end
|
|
10
11
|
end
|
data/init.rb
CHANGED
data/lib/friendly_id.rb
CHANGED
data/lib/friendly_id/helpers.rb
CHANGED
data/lib/friendly_id/slug.rb
CHANGED
|
@@ -35,9 +35,7 @@ class Slug < ActiveRecord::Base
|
|
|
35
35
|
def normalize(slug_text)
|
|
36
36
|
return "" if slug_text.nil? || slug_text == ""
|
|
37
37
|
ActiveSupport::Multibyte.proxy_class.new(slug_text.to_s).normalize(:kc).
|
|
38
|
-
|
|
39
|
-
# characters. Bug in Ruby?
|
|
40
|
-
gsub(/[\W|¡|¿]/u, ' ').
|
|
38
|
+
gsub(/[\W]/u, ' ').
|
|
41
39
|
strip.
|
|
42
40
|
gsub(/\s+/u, '-').
|
|
43
41
|
gsub(/-\z/u, '').
|
|
@@ -45,10 +43,6 @@ class Slug < ActiveRecord::Base
|
|
|
45
43
|
to_s
|
|
46
44
|
end
|
|
47
45
|
|
|
48
|
-
def postnormalize(string)
|
|
49
|
-
string.gs
|
|
50
|
-
end
|
|
51
|
-
|
|
52
46
|
def parse(friendly_id)
|
|
53
47
|
name, sequence = friendly_id.split('--')
|
|
54
48
|
sequence ||= "1"
|
|
@@ -77,10 +71,6 @@ class Slug < ActiveRecord::Base
|
|
|
77
71
|
|
|
78
72
|
private
|
|
79
73
|
|
|
80
|
-
def chars_func
|
|
81
|
-
"".respond_to?(:mb_chars) ? :mb_chars : :chars
|
|
82
|
-
end
|
|
83
|
-
|
|
84
74
|
end
|
|
85
75
|
|
|
86
76
|
# Whether or not this slug is the most recent of its owner's slugs.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
module FriendlyId::SluggableClassMethods
|
|
2
4
|
|
|
3
5
|
include FriendlyId::Helpers
|
|
4
|
-
|
|
6
|
+
|
|
5
7
|
def self.extended(base) #:nodoc:#
|
|
6
8
|
|
|
7
9
|
class << base
|
|
@@ -16,7 +18,7 @@ module FriendlyId::SluggableClassMethods
|
|
|
16
18
|
def find_one_with_friendly(id_or_name, options) #:nodoc:#
|
|
17
19
|
|
|
18
20
|
scope = options.delete(:scope)
|
|
19
|
-
return find_one_without_friendly(id_or_name, options) if id_or_name.is_a?(
|
|
21
|
+
return find_one_without_friendly(id_or_name, options) if id_or_name.is_a?(Integer)
|
|
20
22
|
|
|
21
23
|
find_options = {:select => "#{self.table_name}.*"}
|
|
22
24
|
find_options[:joins] = :slugs unless options[:include] && [*options[:include]].flatten.include?(:slugs)
|
|
@@ -111,4 +113,4 @@ module FriendlyId::SluggableClassMethods
|
|
|
111
113
|
return slugs, ids
|
|
112
114
|
end
|
|
113
115
|
|
|
114
|
-
end
|
|
116
|
+
end
|
data/lib/friendly_id/version.rb
CHANGED
data/lib/tasks/friendly_id.rake
CHANGED
data/test/models/post.rb
CHANGED
data/test/non_slugged_test.rb
CHANGED
data/test/schema.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
ActiveRecord::Schema.define(:version => 1) do
|
|
2
4
|
|
|
3
5
|
create_table "books", :force => true do |t|
|
|
@@ -12,6 +14,7 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
|
12
14
|
create_table "posts", :force => true do |t|
|
|
13
15
|
t.column "title", "string"
|
|
14
16
|
t.column "content", "text"
|
|
17
|
+
t.column "published", "boolean", :default => false
|
|
15
18
|
t.column "created_at", "datetime"
|
|
16
19
|
t.column "updated_at", "datetime"
|
|
17
20
|
end
|
data/test/scoped_model_test.rb
CHANGED
data/test/slugged_model_test.rb
CHANGED
|
@@ -11,7 +11,8 @@ class SluggedModelTest < Test::Unit::TestCase
|
|
|
11
11
|
Post.delete_all
|
|
12
12
|
Person.delete_all
|
|
13
13
|
Slug.delete_all
|
|
14
|
-
|
|
14
|
+
Thing.delete_all
|
|
15
|
+
@post = Post.new :title => "Test post", :content => "Test content", :published => true
|
|
15
16
|
@post.save!
|
|
16
17
|
end
|
|
17
18
|
|
|
@@ -126,6 +127,12 @@ class SluggedModelTest < Test::Unit::TestCase
|
|
|
126
127
|
end
|
|
127
128
|
end
|
|
128
129
|
|
|
130
|
+
# This emulates a fairly common issue where id's generated by fixtures are very high.
|
|
131
|
+
should "continue to admit very large ids" do
|
|
132
|
+
Thing.connection.execute("INSERT INTO things (id, name) VALUES (2147483647, 'big')")
|
|
133
|
+
assert Thing.find(2147483647)
|
|
134
|
+
end
|
|
135
|
+
|
|
129
136
|
context "and configured to strip diacritics" do
|
|
130
137
|
setup do
|
|
131
138
|
Post.friendly_id_options = Post.friendly_id_options.merge(:strip_diacritics => true)
|
|
@@ -236,7 +243,7 @@ class SluggedModelTest < Test::Unit::TestCase
|
|
|
236
243
|
context "when using an array as the find argument" do
|
|
237
244
|
|
|
238
245
|
setup do
|
|
239
|
-
@post2 = Post.create!(:title => "another post", :content => "more content")
|
|
246
|
+
@post2 = Post.create!(:title => "another post", :content => "more content", :published => true)
|
|
240
247
|
end
|
|
241
248
|
|
|
242
249
|
should "return results when passed an array of non-friendly ids" do
|
|
@@ -247,6 +254,10 @@ class SluggedModelTest < Test::Unit::TestCase
|
|
|
247
254
|
assert_equal 2, Post.find([@post.friendly_id, @post2.friendly_id]).size
|
|
248
255
|
end
|
|
249
256
|
|
|
257
|
+
should "return results when searching using a named scope" do
|
|
258
|
+
assert_equal 2, Post.published.find([@post.id, @post2.id]).size
|
|
259
|
+
end
|
|
260
|
+
|
|
250
261
|
should "return results when passed a mixed array of friendly and non-friendly ids" do
|
|
251
262
|
assert_equal 2, Post.find([@post.friendly_id, @post2.id]).size
|
|
252
263
|
end
|
|
@@ -277,4 +288,4 @@ class SluggedModelTest < Test::Unit::TestCase
|
|
|
277
288
|
|
|
278
289
|
end
|
|
279
290
|
|
|
280
|
-
end
|
|
291
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
2
4
|
$:.unshift(File.dirname(__FILE__))
|
|
3
5
|
$KCODE = 'UTF8' if RUBY_VERSION < '1.9'
|
|
4
6
|
$VERBOSE = false
|
|
5
|
-
require 'rubygems'
|
|
6
7
|
require 'test/unit'
|
|
7
8
|
require 'contest'
|
|
8
9
|
# You can use "rake test AR_VERSION=2.0.5" to test against 2.0.5, for example.
|
|
@@ -13,7 +14,6 @@ if ENV["AR_VERSION"]
|
|
|
13
14
|
end
|
|
14
15
|
require 'active_record'
|
|
15
16
|
require 'active_support'
|
|
16
|
-
|
|
17
17
|
require 'friendly_id'
|
|
18
18
|
require 'models/post'
|
|
19
19
|
require 'models/person'
|
|
@@ -24,16 +24,6 @@ require 'models/novel'
|
|
|
24
24
|
require 'models/thing'
|
|
25
25
|
require 'models/event'
|
|
26
26
|
|
|
27
|
-
# Borrowed from ActiveSupport
|
|
28
|
-
def silence_stream(stream)
|
|
29
|
-
old_stream = stream.dup
|
|
30
|
-
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
|
31
|
-
stream.sync = true
|
|
32
|
-
yield
|
|
33
|
-
ensure
|
|
34
|
-
stream.reopen(old_stream)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
27
|
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
|
|
38
28
|
silence_stream(STDOUT) do
|
|
39
29
|
load(File.dirname(__FILE__) + "/schema.rb")
|
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: 2.1.
|
|
4
|
+
version: 2.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Norman Clarke
|
|
@@ -32,7 +32,7 @@ cert_chain:
|
|
|
32
32
|
h7fbBRfStxI=
|
|
33
33
|
-----END CERTIFICATE-----
|
|
34
34
|
|
|
35
|
-
date: 2009-
|
|
35
|
+
date: 2009-09-01 00:00:00 -03:00
|
|
36
36
|
default_executable:
|
|
37
37
|
dependencies:
|
|
38
38
|
- !ruby/object:Gem::Dependency
|
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
163
163
|
requirements: []
|
|
164
164
|
|
|
165
165
|
rubyforge_project: friendly-id
|
|
166
|
-
rubygems_version: 1.3.
|
|
166
|
+
rubygems_version: 1.3.4
|
|
167
167
|
signing_key:
|
|
168
168
|
specification_version: 3
|
|
169
169
|
summary: A comprehensive slugging and pretty-URL plugin for ActiveRecord.
|
metadata.gz.sig
CHANGED
|
Binary file
|