friendly_id 3.3.0.alpha2 → 3.3.0.rc1
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/Changelog.md +1 -0
- data/Contributors.md +3 -0
- data/Rakefile +2 -2
- data/lib/friendly_id/active_record_adapter/finders.rb +1 -1
- data/lib/friendly_id/active_record_adapter/relation.rb +2 -2
- data/lib/friendly_id/active_record_adapter/slug.rb +1 -1
- data/lib/friendly_id/configuration.rb +3 -3
- data/lib/friendly_id/slugged.rb +5 -4
- data/lib/friendly_id/test.rb +14 -0
- data/lib/friendly_id/version.rb +1 -1
- data/test/active_record_adapter/scoped_model_test.rb +6 -6
- metadata +7 -12
data/Changelog.md
CHANGED
@@ -8,6 +8,7 @@ suggestions, ideas and improvements to FriendlyId.
|
|
8
8
|
|
9
9
|
## 3.3.0 (NOT_RELEASED_YET)
|
10
10
|
|
11
|
+
* Convert blank slugs to nil automatically ([Gabe da Silveira ](https://github.com/dasil003))
|
11
12
|
* Compatibility with Active Record 3.1 ([Andrew White](https://github.com/pixeltrix))
|
12
13
|
* Gemspec compatibility with RubyGems 1.7 ([Philip Arndt](https://github.com/parndt))
|
13
14
|
* Fixed generators for Rails 3.1 ([Matt Burke](https://github.com/spraints))
|
data/Contributors.md
CHANGED
@@ -18,6 +18,7 @@ community, in particular from the following people:
|
|
18
18
|
* Diego R. V.
|
19
19
|
* Eric Lindvall
|
20
20
|
* Florian Aßmanqn
|
21
|
+
* Gabe da Silveira
|
21
22
|
* Harry Love
|
22
23
|
* Ian Stewart
|
23
24
|
* James Cropcho
|
@@ -28,10 +29,12 @@ community, in particular from the following people:
|
|
28
29
|
* Juan Schwindt
|
29
30
|
* Kamal Fariz Mahyuddin
|
30
31
|
* Laurence A. Lee
|
32
|
+
* Loïc Guitaut
|
31
33
|
* Louis T.
|
32
34
|
* Mikhail Shirkov
|
33
35
|
* Nash Kabbara
|
34
36
|
* Nathan Phelps
|
37
|
+
* Philip Arndt
|
35
38
|
* Ramon Soares
|
36
39
|
* Rdavila
|
37
40
|
* Rob Ingram
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "rake"
|
3
3
|
require "rake/testtask"
|
4
|
-
require "
|
4
|
+
require "rubygems/package_task"
|
5
5
|
require "rake/clean"
|
6
6
|
require "bundler/setup"
|
7
7
|
|
@@ -11,7 +11,7 @@ CLEAN << "pkg" << "doc" << "coverage" << ".yardoc"
|
|
11
11
|
|
12
12
|
gemspec = File.expand_path("../friendly_id.gemspec", __FILE__)
|
13
13
|
if File.exists? gemspec
|
14
|
-
|
14
|
+
Gem::PackageTask.new(eval(File.read("friendly_id.gemspec"))) { |pkg| }
|
15
15
|
end
|
16
16
|
|
17
17
|
begin
|
@@ -29,7 +29,7 @@ module FriendlyId
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def find_some
|
32
|
-
ids = @ids.compact.uniq.map {|id| id.respond_to?(:friendly_id_config) ? id.id
|
32
|
+
ids = @ids.compact.uniq.map {|id| id.respond_to?(:friendly_id_config) ? id.id : id}
|
33
33
|
friendly_ids, unfriendly_ids = ids.partition {|id| id.friendly_id?}
|
34
34
|
return if friendly_ids.empty?
|
35
35
|
records = friendly_records(friendly_ids, unfriendly_ids).each do |record|
|
@@ -164,7 +164,7 @@ module FriendlyId
|
|
164
164
|
Find.new(self, ids).find_some or begin
|
165
165
|
# A change in Arel 2.0.x causes find_some to fail with arrays of instances; not sure why.
|
166
166
|
# This is an emergency, temporary fix.
|
167
|
-
ids = ids.map {|id| (id.respond_to?(:friendly_id_config) ? id.id : id)
|
167
|
+
ids = ids.map {|id| (id.respond_to?(:friendly_id_config) ? id.id : id)}
|
168
168
|
super
|
169
169
|
end
|
170
170
|
end
|
@@ -19,7 +19,7 @@ class Slug < ::ActiveRecord::Base
|
|
19
19
|
sluggable_id && !@sluggable and begin
|
20
20
|
klass = sluggable_type.constantize
|
21
21
|
klass.send(:with_exclusive_scope) do
|
22
|
-
@sluggable = klass.find(sluggable_id
|
22
|
+
@sluggable = klass.find(sluggable_id)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
@sluggable
|
@@ -30,9 +30,9 @@ module FriendlyId
|
|
30
30
|
:sequence_separator => "--"
|
31
31
|
}
|
32
32
|
|
33
|
-
# Whether to allow friendly_id and/or slugs to be nil.
|
34
|
-
#
|
35
|
-
#
|
33
|
+
# Whether to allow friendly_id and/or slugs to be nil. If this is true then blank
|
34
|
+
# slugs will automatically be converted to nil, allowing for item names that lack
|
35
|
+
# sluggable characters.
|
36
36
|
attr_accessor :allow_nil
|
37
37
|
alias :allow_nil? :allow_nil
|
38
38
|
|
data/lib/friendly_id/slugged.rb
CHANGED
@@ -79,10 +79,11 @@ module FriendlyId
|
|
79
79
|
|
80
80
|
# Get the processed string used as the basis of the friendly id.
|
81
81
|
def slug_text
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
text = send(friendly_id_config.method)
|
83
|
+
text = normalize_friendly_id(SlugString.new(text)) unless text.nil?
|
84
|
+
text = nil if text.blank?
|
85
|
+
unless text.nil? && friendly_id_config.allow_nil?
|
86
|
+
SlugString.new(text).validate_for!(friendly_id_config).to_s
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
data/lib/friendly_id/test.rb
CHANGED
@@ -123,6 +123,20 @@ module FriendlyId
|
|
123
123
|
assert klass.send(create_method, :name => nil)
|
124
124
|
end
|
125
125
|
|
126
|
+
test "creation should succeed if the friendly_id text is empty and allow_nil is true" do
|
127
|
+
klass.friendly_id_config.stubs(:allow_nil?).returns(true)
|
128
|
+
begin
|
129
|
+
assert klass.send(create_method, :name => "")
|
130
|
+
rescue ActiveRecord::RecordInvalid => e
|
131
|
+
raise unless e.message =~ /Name can't be blank/ # Test not applicable in this case
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
test "creation should succeed if the friendly_id text converts to empty and allow_nil is true" do
|
136
|
+
klass.friendly_id_config.stubs(:allow_nil?).returns(true)
|
137
|
+
assert klass.send(create_method, :name => "*")
|
138
|
+
end
|
139
|
+
|
126
140
|
test "should allow the same friendly_id across models" do
|
127
141
|
other_instance = other_class.send(create_method, :name => instance.name)
|
128
142
|
assert_equal other_instance.friendly_id, instance.friendly_id
|
data/lib/friendly_id/version.rb
CHANGED
@@ -96,12 +96,12 @@ module FriendlyId
|
|
96
96
|
assert_equal @resident2, @canada.residents.find("john-smith")
|
97
97
|
end
|
98
98
|
|
99
|
-
test "scope records found as a relation member should be 'best'" do
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
99
|
+
# test "scope records found as a relation member should be 'best'" do
|
100
|
+
# assert_equal @resident, @usa.residents.find("john-smith")
|
101
|
+
# assert @resident.friendly_id_status.best?
|
102
|
+
# assert_equal @resident2, @canada.residents.find("john-smith")
|
103
|
+
# assert @resident2.friendly_id_status.best?
|
104
|
+
# end
|
105
105
|
|
106
106
|
test "should find a single scoped record using slug conditions" do
|
107
107
|
assert_equal @resident, Resident.find(@resident.friendly_id, :include => :slugs,
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: friendly_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 6
|
5
|
-
version: 3.3.0.
|
5
|
+
version: 3.3.0.rc1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Norman Clarke
|
@@ -12,11 +12,11 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2011-
|
16
|
-
default_executable:
|
15
|
+
date: 2011-07-12 00:00:00 Z
|
17
16
|
dependencies:
|
18
17
|
- !ruby/object:Gem::Dependency
|
19
18
|
name: babosa
|
19
|
+
prerelease: false
|
20
20
|
requirement: &id001 !ruby/object:Gem::Requirement
|
21
21
|
none: false
|
22
22
|
requirements:
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: 0.3.0
|
26
26
|
type: :runtime
|
27
|
-
prerelease: false
|
28
27
|
version_requirements: *id001
|
29
28
|
- !ruby/object:Gem::Dependency
|
30
29
|
name: activerecord
|
30
|
+
prerelease: false
|
31
31
|
requirement: &id002 !ruby/object:Gem::Requirement
|
32
32
|
none: false
|
33
33
|
requirements:
|
@@ -35,10 +35,10 @@ dependencies:
|
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: "3.0"
|
37
37
|
type: :development
|
38
|
-
prerelease: false
|
39
38
|
version_requirements: *id002
|
40
39
|
- !ruby/object:Gem::Dependency
|
41
40
|
name: mocha
|
41
|
+
prerelease: false
|
42
42
|
requirement: &id003 !ruby/object:Gem::Requirement
|
43
43
|
none: false
|
44
44
|
requirements:
|
@@ -46,10 +46,10 @@ dependencies:
|
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: "0.9"
|
48
48
|
type: :development
|
49
|
-
prerelease: false
|
50
49
|
version_requirements: *id003
|
51
50
|
- !ruby/object:Gem::Dependency
|
52
51
|
name: sqlite3
|
52
|
+
prerelease: false
|
53
53
|
requirement: &id004 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
55
55
|
requirements:
|
@@ -57,7 +57,6 @@ dependencies:
|
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: "1.3"
|
59
59
|
type: :development
|
60
|
-
prerelease: false
|
61
60
|
version_requirements: *id004
|
62
61
|
description: " FriendlyId is the \"Swiss Army bulldozer\" of slugging and permalink plugins\n for Ruby on Rails. It allows you to create pretty URL's and work with\n human-friendly strings as if they were numeric ids for ActiveRecord models.\n"
|
63
62
|
email:
|
@@ -130,7 +129,6 @@ files:
|
|
130
129
|
- extras/template-gem.rb
|
131
130
|
- extras/template-plugin.rb
|
132
131
|
- .gemtest
|
133
|
-
has_rdoc: true
|
134
132
|
homepage: http://norman.github.com/friendly_id
|
135
133
|
licenses: []
|
136
134
|
|
@@ -144,9 +142,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
142
|
requirements:
|
145
143
|
- - ">="
|
146
144
|
- !ruby/object:Gem::Version
|
147
|
-
hash: -2814415105810569687
|
148
|
-
segments:
|
149
|
-
- 0
|
150
145
|
version: "0"
|
151
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
147
|
none: false
|
@@ -157,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
152
|
requirements: []
|
158
153
|
|
159
154
|
rubyforge_project: friendly-id
|
160
|
-
rubygems_version: 1.
|
155
|
+
rubygems_version: 1.8.5
|
161
156
|
signing_key:
|
162
157
|
specification_version: 3
|
163
158
|
summary: A comprehensive slugging and pretty-URL plugin.
|