slugger 0.3.0 → 0.3.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/VERSION +1 -1
- data/lib/slugger.rb +5 -1
- data/spec/lib/comment_spec.rb +16 -0
- data/spec/lib/post_spec.rb +6 -1
- data/spec/schema.rb +11 -0
- metadata +10 -8
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/slugger.rb
CHANGED
@@ -73,7 +73,11 @@ module Slugger
|
|
73
73
|
# Replace spaces with dashes or custom substitution character
|
74
74
|
s.gsub!(/\ +/, slugger_options[:substitution_char].to_s)
|
75
75
|
s.downcase! if slugger_options[:downcase]
|
76
|
-
|
76
|
+
|
77
|
+
if slugger_options[:max_length]
|
78
|
+
s = s[0..(slugger_options[:max_length] - 1)]
|
79
|
+
s = s[0..-2] if s[-1] == slugger_options[:substitution_char].to_s
|
80
|
+
end
|
77
81
|
|
78
82
|
self.send("#{self.slugger_options[:slug_column]}=", s)
|
79
83
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# class Comment < ActiveRecord::Base
|
4
|
+
# belongs_to :post
|
5
|
+
# has_slug :title, :scope => :post_id
|
6
|
+
# end
|
7
|
+
|
8
|
+
describe Comment do
|
9
|
+
it "should honor scope" do
|
10
|
+
p1 = Post.create(:slug => 'hello-world')
|
11
|
+
p2 = Post.create(:slug => 'hello-world')
|
12
|
+
c1 = Comment.create(:post => p1, :slug => 'first-comment')
|
13
|
+
Comment.create(:post => p2, :slug => 'first-comment').should be_valid
|
14
|
+
Comment.create(:post => p1, :slug => 'first-comment').should_not be_valid
|
15
|
+
end
|
16
|
+
end
|
data/spec/lib/post_spec.rb
CHANGED
@@ -13,11 +13,16 @@ describe Post do
|
|
13
13
|
p = Post.create(:title => "apostrop'hes", :slug => "apostrophes")
|
14
14
|
p.slug.should == "apostrophes"
|
15
15
|
end
|
16
|
-
it "should be limited to 20 characters" do
|
16
|
+
it "slug should be limited to 20 characters" do
|
17
17
|
p = Post.create(
|
18
18
|
:title => "when you write really long titles slugs should be shortened")
|
19
19
|
p.slug.should == "when-you-write-reall"
|
20
20
|
end
|
21
|
+
it "slug should not end with a substitution character" do
|
22
|
+
p = Post.create(
|
23
|
+
:title => "when you write very long titles slugs should be shortened")
|
24
|
+
p.slug.should == "when-you-write-very"
|
25
|
+
end
|
21
26
|
it "should not be valid on duplicate" do
|
22
27
|
p = Post.create(:title => "hello")
|
23
28
|
p.slug.should == "hello"
|
data/spec/schema.rb
CHANGED
@@ -25,6 +25,11 @@ class CreateSchema < ActiveRecord::Migration
|
|
25
25
|
t.string :name
|
26
26
|
t.string :slug_name
|
27
27
|
end
|
28
|
+
create_table :comments, :force => true do |t|
|
29
|
+
t.integer :post_id
|
30
|
+
t.string :title
|
31
|
+
t.string :slug
|
32
|
+
end
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
@@ -33,6 +38,7 @@ CreateSchema.suppress_messages do
|
|
33
38
|
end
|
34
39
|
|
35
40
|
class Post < ActiveRecord::Base
|
41
|
+
has_many :comments
|
36
42
|
has_slug 'title', :max_length => 20
|
37
43
|
end
|
38
44
|
|
@@ -46,3 +52,8 @@ class Edge < ActiveRecord::Base
|
|
46
52
|
:downcase => false,
|
47
53
|
:on_conflict => :concat_random_chars
|
48
54
|
end
|
55
|
+
|
56
|
+
class Comment < ActiveRecord::Base
|
57
|
+
belongs_to :post
|
58
|
+
has_slug :title, :scope => :post_id
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slugger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-13 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70110795330660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70110795330660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70110795330000 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70110795330000
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70110795329540 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 1.3.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70110795329540
|
47
47
|
description: Slugger is yet another slug generator.
|
48
48
|
email:
|
49
49
|
- seth.faxon@gmail.com
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/slugger.rb
|
63
63
|
- lib/slugger/version.rb
|
64
64
|
- slugger.gemspec
|
65
|
+
- spec/lib/comment_spec.rb
|
65
66
|
- spec/lib/edge_spec.rb
|
66
67
|
- spec/lib/post_spec.rb
|
67
68
|
- spec/lib/user_spec.rb
|
@@ -93,6 +94,7 @@ signing_key:
|
|
93
94
|
specification_version: 3
|
94
95
|
summary: Slugger is yet another slug generator.
|
95
96
|
test_files:
|
97
|
+
- spec/lib/comment_spec.rb
|
96
98
|
- spec/lib/edge_spec.rb
|
97
99
|
- spec/lib/post_spec.rb
|
98
100
|
- spec/lib/user_spec.rb
|