Skip to content

Commit

Permalink
Make #to_param aware about keys
Browse files Browse the repository at this point in the history
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
avsej committed Oct 17, 2012
1 parent 2ab7047 commit 8c7eb14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/couchbase/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions test/test_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.