slugable 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/changelog.md +4 -0
- data/lib/slugable/has_slug.rb +4 -4
- data/lib/slugable/version.rb +1 -1
- data/spec/slugable/has_slug_spec.rb +12 -0
- metadata +4 -4
data/changelog.md
CHANGED
data/lib/slugable/has_slug.rb
CHANGED
@@ -101,9 +101,9 @@ module Slugable
|
|
101
101
|
# def to_slug
|
102
102
|
# if respond_to?(:path_ids)
|
103
103
|
# slugs = if true
|
104
|
-
# path_ids.map{|id| self.class.cached_slug(id)}.select{|i| i.size > 0 }
|
104
|
+
# path_ids.map{|id| self.class.cached_slug(id)}.compact.select{|i| i.size > 0 }
|
105
105
|
# else
|
106
|
-
# path.map{|record| record.send(:"slug")}.select{|i| i.size > 0 }
|
106
|
+
# path.map{|record| record.send(:"slug")}.compact.select{|i| i.size > 0 }
|
107
107
|
# end
|
108
108
|
# slugs.empty? ? "" : slugs
|
109
109
|
# else
|
@@ -114,9 +114,9 @@ module Slugable
|
|
114
114
|
def to_#{to}
|
115
115
|
if respond_to?(:path_ids)
|
116
116
|
slugs = if #{cache_tree}
|
117
|
-
path_ids.map{|id| self.class.cached_#{to}(id)}.select{|i| i.size > 0 }
|
117
|
+
path_ids.map{|id| self.class.cached_#{to}(id)}.compact.select{|i| i.size > 0 }
|
118
118
|
else
|
119
|
-
path.map{|record| record.send(:"#{to}")}.select{|i| i.size > 0 }
|
119
|
+
path.map{|record| record.send(:"#{to}")}.compact.select{|i| i.size > 0 }
|
120
120
|
end
|
121
121
|
slugs.empty? ? "" : slugs
|
122
122
|
else
|
data/lib/slugable/version.rb
CHANGED
@@ -144,6 +144,18 @@ describe Slugable::HasSlug do
|
|
144
144
|
|
145
145
|
child.to_slug.should eq ["root", "child"]
|
146
146
|
end
|
147
|
+
|
148
|
+
it "should skip nil values from slug path" do
|
149
|
+
root = Category.create!(:name => "root", :slug => "root")
|
150
|
+
child = Category.new(:name => "child", :slug => "child")
|
151
|
+
child.parent = root
|
152
|
+
child.save!
|
153
|
+
|
154
|
+
Category.update_all({:slug => nil}, {:id => root.id})
|
155
|
+
Category.clear_cached_slugs
|
156
|
+
|
157
|
+
child.to_slug.should eq ["child"]
|
158
|
+
end
|
147
159
|
end
|
148
160
|
end
|
149
161
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slugable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -159,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
segments:
|
161
161
|
- 0
|
162
|
-
hash:
|
162
|
+
hash: -494734928332233680
|
163
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
164
|
none: false
|
165
165
|
requirements:
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
segments:
|
170
170
|
- 0
|
171
|
-
hash:
|
171
|
+
hash: -494734928332233680
|
172
172
|
requirements: []
|
173
173
|
rubyforge_project:
|
174
174
|
rubygems_version: 1.8.24
|