diff --git a/lib/database.rb b/lib/database.rb index 57f6937..898b5c7 100644 --- a/lib/database.rb +++ b/lib/database.rb @@ -32,6 +32,11 @@ class CouchRest end end + def delete doc + slug = CGI.escape(doc['_id']) + CouchRest.delete "#{@root}/#{slug}?rev=#{doc['_rev']}" + end + def delete! CouchRest.delete @root end diff --git a/spec/database_spec.rb b/spec/database_spec.rb index 7c6ebf5..c04f3ca 100644 --- a/spec/database_spec.rb +++ b/spec/database_spec.rb @@ -69,6 +69,20 @@ describe CouchRest::Database do end end + describe "DELETE existing document" do + before(:each) do + @r = @db.save({'lemons' => 'from texas', 'and' => 'spain'}) + @docid = "http://example.com/stuff.cgi?things=and%20stuff" + @db.save({'_id' => @docid, 'will-exist' => 'here'}) + end + it "should work" do + doc = @db.get(@r['id']) + doc['and'].should == 'spain' + @db.delete doc + lambda{@db.get @r['id']}.should raise_error + end + end + it "should list documents" do 5.times do @db.save({'another' => 'doc', 'will-exist' => 'anywhere'}) @@ -98,4 +112,5 @@ describe CouchRest::Database do end end + end \ No newline at end of file