Permalink
Browse files

Fixing incorrectly generated document URIs with testing

  • Loading branch information...
1 parent 2f2c507 commit bb2c7e87ad5c0b6b70e79f2afd256ca9afb21716 @samlown committed Sep 28, 2009
Showing with 10 additions and 2 deletions.
  1. +1 −1 lib/couchrest/core/document.rb
  2. +9 −1 spec/couchrest/core/document_spec.rb
@@ -65,7 +65,7 @@ def copy(dest)
# Returns the CouchDB uri for the document
def uri(append_rev = false)
return nil if new?
- couch_uri = "http://#{database.root}/#{CGI.escape(id)}"
+ couch_uri = "#{database.root}/#{CGI.escape(id)}"
if append_rev == true
couch_uri << "?rev=#{rev}"
elsif append_rev.kind_of?(Integer)
@@ -83,6 +83,14 @@ class Video < CouchRest::Document; end
@doc.id.should == @resp["id"]
@doc.rev.should == @resp["rev"]
end
+ it "should generate a correct URI" do
+ @doc.uri.should == "#{@db.root}/#{@doc.id}"
+ URI.parse(@doc.uri).to_s.should == @doc.uri
+ end
+ it "should generate a correct URI with revision" do
+ @doc.uri(true).should == "#{@db.root}/#{@doc.id}?rev=#{@doc.rev}"
+ URI.parse(@doc.uri(true)).to_s.should == @doc.uri(true)
+ end
end
describe "bulk saving" do
@@ -264,4 +272,4 @@ def append_attachment(name='test.html', attach=@attach)
end
end
-end
+end

0 comments on commit bb2c7e8

Please sign in to comment.