vanity_slug 0.0.3 → 0.0.4
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/README.md +7 -10
- data/lib/vanity_slug/active_record.rb +1 -1
- data/lib/vanity_slug/version.rb +1 -1
- data/spec/vanity_slug_spec.rb +23 -12
- metadata +2 -2
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# VanitySlug
|
2
2
|
|
3
|
-
Add unique vanity urls to any model without use of redirects. Middleware matches routes that don't resolve with the Rails router and checks if they match a slug from any vanity-slug enabled model. If found, the env["PATH_INFO"] is changed like so:
|
3
|
+
Add unique vanity urls to any model without use of redirects. Middleware matches routes that don't resolve with the Rails router and checks if they match a slug from any vanity-slug enabled model. If found, the `env["PATH_INFO"]` is changed like so:
|
4
4
|
|
5
5
|
Given a Post with slug "my-post-title" and id 1, and a Category with slug "the-category" and id 2:
|
6
6
|
|
@@ -32,7 +32,7 @@ Or install it yourself as:
|
|
32
32
|
* action: route vanity slug will resolve to (default: RESTful show route i.e. "/posts/:id"). Route must be defined.
|
33
33
|
* field_to_slug: which column to use in vanity slug generation (default: :name).
|
34
34
|
* slug_field: which column to store generated slug (default: :slug).
|
35
|
-
* uniqueness_scope: method or attribute to use as uniqueness
|
35
|
+
* uniqueness_scope: method or attribute to use as uniqueness scope in slug
|
36
36
|
generation (default: nil).
|
37
37
|
|
38
38
|
#### Config
|
@@ -52,20 +52,17 @@ Use to scope the finder based on rack env, i.e. host parameter. Should return a
|
|
52
52
|
|
53
53
|
```ruby
|
54
54
|
class Post < ActiveRecord::Base
|
55
|
-
|
55
|
+
attr_accesible :title
|
56
56
|
|
57
|
-
has_vanity_slug
|
58
|
-
field_to_slug: :title,
|
59
|
-
uniqueness_scope: :site_id
|
57
|
+
has_vanity_slug field_to_slug: :title, uniqueness_scope: :site_id
|
60
58
|
|
61
59
|
belongs_to :site
|
62
60
|
end
|
63
61
|
|
64
62
|
class Category < ActiveRecord::Base
|
65
|
-
|
63
|
+
attr_accesible :name
|
66
64
|
|
67
|
-
has_vanity_slug action: "/categories/:id/slug",
|
68
|
-
slug_field: :permalink
|
65
|
+
has_vanity_slug action: "/categories/:id/slug", slug_field: :permalink
|
69
66
|
|
70
67
|
belongs_to :site
|
71
68
|
end
|
@@ -79,7 +76,7 @@ Use to scope the finder based on rack env, i.e. host parameter. Should return a
|
|
79
76
|
|
80
77
|
```ruby
|
81
78
|
VanitySlug.path_scope = Proc.new{|env|
|
82
|
-
{
|
79
|
+
{ site_id: Site.find_by_domain(env["HTTP_HOST"]).try(:id) }
|
83
80
|
}
|
84
81
|
```
|
85
82
|
|
data/lib/vanity_slug/version.rb
CHANGED
data/spec/vanity_slug_spec.rb
CHANGED
@@ -28,21 +28,22 @@ class Site < ActiveRecord::Base
|
|
28
28
|
end
|
29
29
|
|
30
30
|
describe VanitySlug do
|
31
|
-
|
32
|
-
|
33
|
-
let(:str_slugged) { "slug-me" }
|
31
|
+
let(:str) { "slug me" }
|
32
|
+
let(:str_slugged) { "slug-me" }
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
before do
|
35
|
+
@site_1 = Site.create domain: "a.com"
|
36
|
+
@site_2 = Site.create domain: "b.com"
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
@post_1 = Post.create title: str, site: @site_1
|
39
|
+
@post_2 = Post.create title: str, site: @site_1
|
40
|
+
@post_3 = Post.create title: str, site: @site_2
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
@category_1 = Category.create name: str, site: @site_1
|
43
|
+
@category_2 = Category.create name: str, site: @site_2
|
44
|
+
end
|
45
|
+
|
46
|
+
context "setting slugs" do
|
46
47
|
|
47
48
|
it { @post_1.slug.should eq str_slugged }
|
48
49
|
it { @post_2.slug.should eq str_slugged+"-1" }
|
@@ -80,4 +81,14 @@ describe VanitySlug do
|
|
80
81
|
VanitySlug.find(env).should be_false
|
81
82
|
end
|
82
83
|
end
|
84
|
+
|
85
|
+
context "updating slug source column" do
|
86
|
+
let(:new_title) { "#{str} edit" }
|
87
|
+
before do
|
88
|
+
@post_1.update_attributes title: new_title
|
89
|
+
end
|
90
|
+
|
91
|
+
it { @post_1.should be_valid }
|
92
|
+
it { @post_1.title.should eq new_title }
|
93
|
+
end
|
83
94
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanity_slug
|
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: 2012-
|
12
|
+
date: 2012-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: root level Vanity Slug for any model
|
15
15
|
email:
|