slugable 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/changelog.md +5 -1
- data/lib/slugable/has_slug.rb +2 -2
- data/lib/slugable/version.rb +1 -1
- data/spec/slugable/has_slug_spec.rb +13 -3
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
data/changelog.md
CHANGED
data/lib/slugable/has_slug.rb
CHANGED
@@ -23,11 +23,11 @@ module Slugable
|
|
23
23
|
# generate this
|
24
24
|
#
|
25
25
|
# def fill_slug
|
26
|
-
# self.slug = name
|
26
|
+
# self.slug = name if slug.blank? || slug.parameterize.blank?
|
27
27
|
# end
|
28
28
|
code =<<-method
|
29
29
|
def fill_slug_from_#{from}_to_#{to}
|
30
|
-
self.#{to} = #{from}
|
30
|
+
self.#{to} = #{from} if #{to}.blank? || #{to}.parameterize.blank?
|
31
31
|
end
|
32
32
|
method
|
33
33
|
class_eval(code)
|
data/lib/slugable/version.rb
CHANGED
@@ -41,6 +41,11 @@ describe Slugable::HasSlug do
|
|
41
41
|
item.slug.should eq "my-name-is"
|
42
42
|
end
|
43
43
|
|
44
|
+
it "should fill in slug from attribute name if parameterize version of slug is blank", :focus => true do
|
45
|
+
item = Item.create!(:name => "my name is", :slug => "/")
|
46
|
+
item.slug.should eq "my-name-is"
|
47
|
+
end
|
48
|
+
|
44
49
|
it "should only parametrize slug attribute if slug is present" do
|
45
50
|
item = Item.create!(:name => "my name is", :slug => "my url")
|
46
51
|
item.slug.should eq "my-url"
|
@@ -56,11 +61,16 @@ describe Slugable::HasSlug do
|
|
56
61
|
Page.new.should respond_to :format_slug_from_title_to_seo_url
|
57
62
|
end
|
58
63
|
|
59
|
-
it "should fill in slug parameter from attribute
|
64
|
+
it "should fill in slug parameter from attribute title and parametrize it" do
|
60
65
|
page = Page.create!(:title => "my name is")
|
61
66
|
page.seo_url.should eq "my-name-is"
|
62
67
|
end
|
63
68
|
|
69
|
+
it "should fill in slug parameter from attribute title if parameterize version of slug is blank" do
|
70
|
+
page = Page.create!(:title => "my name is", :seo_url => "/")
|
71
|
+
page.seo_url.should eq "my-name-is"
|
72
|
+
end
|
73
|
+
|
64
74
|
it "should only parametrize slug attribute if slug is present" do
|
65
75
|
page = Page.create!(:title => "my name is", :seo_url => "my url")
|
66
76
|
page.seo_url.should eq "my-url"
|
@@ -69,7 +79,7 @@ describe Slugable::HasSlug do
|
|
69
79
|
|
70
80
|
describe "to_slug" do
|
71
81
|
context "default options" do
|
72
|
-
it "should define
|
82
|
+
it "should define method to_seo_url" do
|
73
83
|
Item.new.should respond_to :to_slug
|
74
84
|
end
|
75
85
|
|
@@ -80,7 +90,7 @@ describe Slugable::HasSlug do
|
|
80
90
|
end
|
81
91
|
|
82
92
|
context "given options" do
|
83
|
-
it "should define
|
93
|
+
it "should define method to_seo_url" do
|
84
94
|
Page.new.should respond_to :to_seo_url
|
85
95
|
end
|
86
96
|
|
data/spec/spec_helper.rb
CHANGED
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.2
|
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: 2012-
|
12
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|