seofy 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,7 +30,13 @@ Usage
30
30
  seofy :source => :title, :adapter => :base36, :adapter_option => {:length => 3, :column => :slug }
31
31
  end
32
32
 
33
- User.for_seofy("SLUG")
33
+ User.for_seofy("a-name-slug")
34
+
35
+ `for_seofy_with_short_url` will support get record only use slug
36
+
37
+ User.for_seofy_with_short_url("slug")
38
+ User.for_seofy_with_short_url("a-name-slug")
39
+
34
40
 
35
41
  and we won't override `to_param` method, we create new one `seofy_param`
36
42
 
@@ -20,6 +20,14 @@ module Seofy
20
20
  def for_seofy(param)
21
21
  self.send("find_by_#{seofy_adapter.column}", param.split("-").last)
22
22
  end
23
+
24
+ def for_seofy_with_short_url(param)
25
+ if param.to_s.include?("-")
26
+ for_seofy(param)
27
+ else
28
+ self.send("find_by_#{seofy_adapter.column}", param)
29
+ end
30
+ end
23
31
  end
24
32
 
25
33
  module InstanceMethods
@@ -1,3 +1,3 @@
1
1
  module Seofy
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -27,13 +27,26 @@ describe Seofy::ActiveRecord do
27
27
  end
28
28
  end
29
29
 
30
- describe "for_slug" do
30
+ describe "for_seofy" do
31
31
  it "should get slug from id and find record use it" do
32
32
  @klass.should_receive(:seofy_adapter).and_return double(:column => "id")
33
33
  @klass.should_receive("find_by_id").with("123")
34
34
  @klass.for_seofy("a-b-c-123")
35
35
  end
36
36
  end
37
+
38
+ describe "for_seofy_with_short_url" do
39
+ it "should use for_seofy if contain '-'" do
40
+ @klass.should_receive("for_seofy").with("a-b-c-123")
41
+ @klass.for_seofy_with_short_url("a-b-c-123")
42
+ end
43
+
44
+ it "should find record use slug column if doesn't contain '-'" do
45
+ @klass.should_receive(:seofy_adapter).and_return double(:column => "id")
46
+ @klass.should_receive("find_by_id").with("123")
47
+ @klass.for_seofy_with_short_url("123")
48
+ end
49
+ end
37
50
  end
38
51
 
39
52
  context "instance methods" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seofy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Allen Wei