Skip to content

Commit

Permalink
add delete document to couchdb utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Janda committed Apr 26, 2012
1 parent c78b722 commit 2012344
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/util/couchdb.js
Expand Up @@ -40,14 +40,21 @@ CouchDb.prototype.createDocument = function(data, callback) {
this.getUuid(function(uuid) {
self.request({
method: 'PUT',
path: '/' + self.database + '/' + uuid,
path: self._documentPath(uuid),
data: data
}, callback);
});
}

CouchDb.prototype.deleteDocument = function(id, callback) {

this.request({
method: 'DELETE',
path: this._documentPath(id)
}, callback);
}

CouchDb.prototype._documentPath = function(id) {
return '/' + this.database + '/' + id;
}

/*
Expand Down
13 changes: 13 additions & 0 deletions spec/util/couchdbSpec.js
Expand Up @@ -42,6 +42,19 @@ describe('couchdb', function() {
})
})

describe('deleteDocument', function() {
it('should call proper request', function() {
var callback = function() {},
options = { path: '/cqrs/1234', method: 'DELETE'};

spyOn(couchdb, 'request');

couchdb.deleteDocument(1234, callback);

expect(couchdb.request).toHaveBeenCalledWith(options, callback);
})
})

describe('getUuid', function() {
it('should call proper request', function() {
var options = {
Expand Down

0 comments on commit 2012344

Please sign in to comment.