Permalink
Browse files

Make #to_param aware about keys

Change-Id: Ie6eb5a680d040637578634f40a310a9d698fd94e
Reviewed-on: http://review.couchbase.org/21722
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information...
1 parent 2ab7047 commit 8c7eb14d8c1a62f3899ec31abe2929fe9094d8f9 @avsej committed Oct 17, 2012
Showing with 12 additions and 0 deletions.
  1. +7 −0 lib/couchbase/model.rb
  2. +5 −0 test/test_model.rb
View
7 lib/couchbase/model.rb
@@ -756,6 +756,13 @@ def to_key
keys = [id || key]
keys.empty? ? nil : keys
end
+
+ def to_param
+ keys = to_key
+ if keys && !keys.empty?
+ keys.join("-")
+ end
+ end
end
end
View
5 test/test_model.rb
@@ -176,4 +176,9 @@ def test_to_key
assert_equal ["the-key"], Post.new(:key => "the-key").to_key
end
+ def test_to_param
+ assert_equal "the-id", Post.new(:id => "the-id").to_param
+ assert_equal "the-key", Post.new(:key => ["the", "key"]).to_param
+ end
+
end

0 comments on commit 8c7eb14

Please sign in to comment.