seofy 0.0.5 → 0.0.6
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 -1
- data/lib/seofy/active_record.rb +8 -0
- data/lib/seofy/version.rb +1 -1
- data/spec/lib/seofy/active_record_spec.rb +14 -1
- metadata +3 -3
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("
|
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
|
|
data/lib/seofy/active_record.rb
CHANGED
@@ -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
|
data/lib/seofy/version.rb
CHANGED
@@ -27,13 +27,26 @@ describe Seofy::ActiveRecord do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe "
|
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