friendly_id 2.2.0 → 2.2.1
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/History.txt +6 -0
- data/Manifest.txt +0 -1
- data/README.rdoc +11 -4
- data/lib/friendly_id.rb +4 -2
- data/lib/friendly_id/sluggable_class_methods.rb +1 -2
- data/lib/friendly_id/sluggable_instance_methods.rb +8 -6
- data/lib/friendly_id/version.rb +1 -1
- data/test/cached_slug_test.rb +15 -2
- data/test/schema.rb +1 -0
- metadata +2 -3
- data/friendly_id.gemspec +0 -46
data/History.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 2.2.1 2009-10-23
|
2
|
+
|
3
|
+
* 2 minor enhancements:
|
4
|
+
* slug cache now properly caches the slug sequence (closes GH issue #10)
|
5
|
+
* attr_protected is now only invoked on the cached_slug column if attr_accessible has not already been invoked. (closes GH issue #11)
|
6
|
+
|
1
7
|
== 2.2.0 2009-10-19
|
2
8
|
|
3
9
|
* 1 major enhancement:
|
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -172,12 +172,19 @@ Then, redo the slugs:
|
|
172
172
|
|
173
173
|
rake friendly_id:redo_slugs MODEL=User
|
174
174
|
|
175
|
+
This feature exists largely to improve the performance of URL
|
176
|
+
generation, the part of Rails where FriendlyId has the biggest
|
177
|
+
performance impact. FriendlyId never queries against this column, so
|
178
|
+
it's not necessary to add an index on it unless your application does.
|
179
|
+
|
180
|
+
Two warnings when using this feature:
|
181
|
+
|
175
182
|
*DO NOT* forget to redo the slugs, or else this feature will not work!
|
176
183
|
|
177
|
-
Also
|
178
|
-
|
179
|
-
|
180
|
-
|
184
|
+
Also, this feature uses +attr_protected+ to protect the cached_slug
|
185
|
+
column, unless you have already invoked +attr_accessible+. So if you
|
186
|
+
wish to use +attr_accessible+, you must invoke it BEFORE you invoke
|
187
|
+
+has_friendly_id+ in your class.
|
181
188
|
|
182
189
|
==== Using a custom column name:
|
183
190
|
|
data/lib/friendly_id.rb
CHANGED
@@ -42,7 +42,7 @@ module FriendlyId
|
|
42
42
|
# Options:
|
43
43
|
# * <tt>:use_slug</tt> - Defaults to false. Use slugs when you want to use a non-unique text field for friendly ids.
|
44
44
|
# * <tt>:max_length</tt> - Defaults to 255. The maximum allowed length for a slug.
|
45
|
-
# * <tt>:cache_column</tt> - Defaults to nil. Use this column as a cache for generating to_param (experimental).
|
45
|
+
# * <tt>:cache_column</tt> - Defaults to nil. Use this column as a cache for generating to_param (experimental) Note that if you use this option, any calls to +attr_accessible+ must be made BEFORE any calls to has_friendly_id in your class.
|
46
46
|
# * <tt>:strip_diacritics</tt> - Defaults to false. If true, it will remove accents, umlauts, etc. from western characters.
|
47
47
|
# * <tt>:strip_non_ascii</tt> - Defaults to false. If true, it will all non-ascii ([^a-z0-9]) characters.
|
48
48
|
# * <tt>:reserved</tt> - Array of words that are reserved and can't be used as friendly_id's. For sluggable models, if such a word is used, it will raise a FriendlyId::SlugGenerationError. Defaults to ["new", "index"].
|
@@ -79,11 +79,13 @@ module FriendlyId
|
|
79
79
|
extend SluggableClassMethods
|
80
80
|
include SluggableInstanceMethods
|
81
81
|
before_save :set_slug
|
82
|
+
after_save :set_slug_cache
|
82
83
|
if block_given?
|
83
84
|
write_inheritable_attribute :slug_normalizer_block, block
|
84
85
|
end
|
85
86
|
if options[:cache_column]
|
86
|
-
|
87
|
+
# only protect the column if the class is not already using attributes_accessible
|
88
|
+
attr_protected options[:cache_column].to_sym unless accessible_attributes
|
87
89
|
end
|
88
90
|
else
|
89
91
|
require 'friendly_id/non_sluggable_class_methods'
|
@@ -32,15 +32,14 @@ module FriendlyId::SluggableClassMethods
|
|
32
32
|
end
|
33
33
|
|
34
34
|
result
|
35
|
+
|
35
36
|
rescue ActiveRecord::RecordNotFound => e
|
36
37
|
|
37
38
|
if friendly_id_options[:scope]
|
38
39
|
if !scope
|
39
40
|
raise ActiveRecord::RecordNotFound.new("%s; expected scope but got none" % e.message)
|
40
|
-
# e.message << "; expected scope but got none"
|
41
41
|
else
|
42
42
|
raise ActiveRecord::RecordNotFound.new("%s and scope=#{scope}" % e.message)
|
43
|
-
# e.message << " and scope=#{scope}"
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
@@ -118,12 +118,14 @@ private
|
|
118
118
|
# If we're renaming back to a previously used friendly_id, delete the
|
119
119
|
# slug so that we can recycle the name without having to use a sequence.
|
120
120
|
slugs.find(:all, :conditions => {:name => slug_text, :scope => scope}).each { |s| s.destroy }
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
121
|
+
slugs.build slug_attributes
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def set_slug_cache
|
126
|
+
if friendly_id_options[:cache_column] && send(friendly_id_options[:cache_column]) != slug.to_friendly_id
|
127
|
+
send "#{friendly_id_options[:cache_column]}=", slug.to_friendly_id
|
128
|
+
send :update_without_callbacks
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
data/lib/friendly_id/version.rb
CHANGED
data/test/cached_slug_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8!
|
2
|
-
|
2
|
+
require "mocha"
|
3
3
|
|
4
4
|
require File.dirname(__FILE__) + '/test_helper'
|
5
5
|
|
@@ -29,9 +29,22 @@ class CachedSlugModelTest < Test::Unit::TestCase
|
|
29
29
|
should "protect the cached slug value" do
|
30
30
|
@paris.update_attributes(:my_slug => "Madrid")
|
31
31
|
@paris.reload
|
32
|
-
assert_equal
|
32
|
+
assert_equal "paris", @paris.my_slug
|
33
33
|
end
|
34
34
|
|
35
|
+
should "cache the incremented sequence for duplicate slug names" do
|
36
|
+
@paris2 = City.create!(:name => "Paris")
|
37
|
+
assert_equal 2, @paris2.slug.sequence
|
38
|
+
assert_equal "paris--2", @paris2.my_slug
|
39
|
+
end
|
40
|
+
|
41
|
+
should "not update the cached slug column if it has not changed" do
|
42
|
+
@paris.population = 10_000_000
|
43
|
+
@paris.expects(:my_slug=).never
|
44
|
+
@paris.save
|
45
|
+
end
|
46
|
+
|
47
|
+
|
35
48
|
context "found by its friendly id" do
|
36
49
|
|
37
50
|
setup do
|
data/test/schema.rb
CHANGED
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.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-10-
|
14
|
+
date: 2009-10-23 00:00:00 -03:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -84,7 +84,6 @@ files:
|
|
84
84
|
- README.rdoc
|
85
85
|
- Rakefile
|
86
86
|
- config/website.yml
|
87
|
-
- friendly_id.gemspec
|
88
87
|
- generators/friendly_id/friendly_id_generator.rb
|
89
88
|
- generators/friendly_id/templates/create_slugs.rb
|
90
89
|
- generators/friendly_id_20_upgrade/friendly_id_20_upgrade_generator.rb
|
data/friendly_id.gemspec
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{friendly_id}
|
5
|
-
s.version = "2.2.0"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Norman Clarke", "Adrian Mugnolo", "Emilio Tagua"]
|
9
|
-
s.date = %q{2009-09-21}
|
10
|
-
s.description = %q{A comprehensive slugging and pretty-URL plugin for ActiveRecord.}
|
11
|
-
s.email = ["norman@rubysouth.com", "adrian@rubysouth.com", "miloops@gmail.com"]
|
12
|
-
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
13
|
-
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "config/website.yml", "friendly_id.gemspec", "generators/friendly_id/friendly_id_generator.rb", "generators/friendly_id/templates/create_slugs.rb", "generators/friendly_id_20_upgrade/friendly_id_20_upgrade_generator.rb", "generators/friendly_id_20_upgrade/templates/upgrade_friendly_id_to_20.rb", "init.rb", "lib/friendly_id.rb", "lib/friendly_id/helpers.rb", "lib/friendly_id/non_sluggable_class_methods.rb", "lib/friendly_id/non_sluggable_instance_methods.rb", "lib/friendly_id/slug.rb", "lib/friendly_id/sluggable_class_methods.rb", "lib/friendly_id/sluggable_instance_methods.rb", "lib/friendly_id/version.rb", "lib/tasks/friendly_id.rake", "lib/tasks/friendly_id.rb", "test/contest.rb", "test/custom_slug_normalizer_test.rb", "test/models/book.rb", "test/models/country.rb", "test/models/event.rb", "test/models/novel.rb", "test/models/person.rb", "test/models/post.rb", "test/models/thing.rb", "test/models/user.rb", "test/non_slugged_test.rb", "test/schema.rb", "test/scoped_model_test.rb", "test/slug_test.rb", "test/slugged_model_test.rb", "test/sti_test.rb", "test/test_helper.rb"]
|
14
|
-
s.homepage = %q{http://friendly-id.rubyforge.org/}
|
15
|
-
s.rdoc_options = ["--main", "README.rdoc"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{friendly-id}
|
18
|
-
s.rubygems_version = %q{1.3.4}
|
19
|
-
s.summary = %q{A comprehensive slugging and pretty-URL plugin for ActiveRecord.}
|
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"]
|
21
|
-
|
22
|
-
if s.respond_to? :specification_version then
|
23
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
-
s.specification_version = 3
|
25
|
-
|
26
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
-
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0"])
|
28
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 2.0.0"])
|
29
|
-
s.add_development_dependency(%q<newgem>, [">= 1.4.1"])
|
30
|
-
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
31
|
-
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
32
|
-
else
|
33
|
-
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
34
|
-
s.add_dependency(%q<activesupport>, [">= 2.0.0"])
|
35
|
-
s.add_dependency(%q<newgem>, [">= 1.4.1"])
|
36
|
-
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
37
|
-
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
38
|
-
end
|
39
|
-
else
|
40
|
-
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
41
|
-
s.add_dependency(%q<activesupport>, [">= 2.0.0"])
|
42
|
-
s.add_dependency(%q<newgem>, [">= 1.4.1"])
|
43
|
-
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
44
|
-
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
45
|
-
end
|
46
|
-
end
|