vanity_slug 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
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 check in slug
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
- attr_accessible :title, :site
55
+ attr_accesible :title
56
56
 
57
- has_vanity_slug action: "/posts/:id",
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
- attr_accessible :name, :site
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
- { organization_id: Organization.find_by_host(env["HTTP_HOST"]).try(:id) }
79
+ { site_id: Site.find_by_domain(env["HTTP_HOST"]).try(:id) }
83
80
  }
84
81
  ```
85
82
 
@@ -68,7 +68,7 @@ ActiveSupport.on_load :active_record do
68
68
  klass.slug_field => slug_to_check
69
69
  }))
70
70
 
71
- finder = finder.where("id != ?", id) if klass == self.class
71
+ finder = finder.where("id != ?", self.id) if klass.to_s == self.class.to_s
72
72
  finder.count > 0
73
73
  end
74
74
 
@@ -1,3 +1,3 @@
1
1
  module VanitySlug
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -28,21 +28,22 @@ class Site < ActiveRecord::Base
28
28
  end
29
29
 
30
30
  describe VanitySlug do
31
- context "setting slugs" do
32
- let(:str) { "slug me" }
33
- let(:str_slugged) { "slug-me" }
31
+ let(:str) { "slug me" }
32
+ let(:str_slugged) { "slug-me" }
34
33
 
35
- before do
36
- @site_1 = Site.create domain: "a.com"
37
- @site_2 = Site.create domain: "b.com"
34
+ before do
35
+ @site_1 = Site.create domain: "a.com"
36
+ @site_2 = Site.create domain: "b.com"
38
37
 
39
- @post_1 = Post.create title: str, site: @site_1
40
- @post_2 = Post.create title: str, site: @site_1
41
- @post_3 = Post.create title: str, site: @site_2
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
- @category_1 = Category.create name: str, site: @site_1
44
- @category_2 = Category.create name: str, site: @site_2
45
- end
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.3
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-11-13 00:00:00.000000000 Z
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: