Skip to content

Commit

Permalink
Added test case for document handling, fixed bugs on the go
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtus committed Jun 27, 2009
1 parent e661da0 commit 38ab66e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
21 changes: 15 additions & 6 deletions module/node-couch.js
Expand Up @@ -162,12 +162,16 @@ exports.CouchDB = {
doc = doc || {};
var success = options.success;
options.success = function(result) {
doc._id = result._id;
doc._rev = result._rev;
if (success) { success(result); }
if (!result.ok) {
options.error(result);
} else {
doc._id = result.id;
doc._rev = result.rev;
}
if (success) { success(doc); }
};

options.body = toJSON(doc);
options.body = doc;

if (doc._id === undefined) {
this.interact("post", "", 201, options);
Expand All @@ -178,13 +182,18 @@ exports.CouchDB = {

removeDoc : function(doc, options) {
options = options || {};
options.rev = doc._rev;

var success = options.success;
options.success = function(result) {
if (!result.ok) {
options.error(result);
}
delete doc._rev;
if (success) {
success(result);
success(doc);
}
}
};

this.interact("del", doc._id, 200, options);
},
Expand Down
2 changes: 1 addition & 1 deletion test/mjsunit/test-activeTasks.js
Expand Up @@ -2,7 +2,7 @@ include("mjsunit.js");
include("../../module/node-couch.js");

function unwantedError(result) {
throw new Exception("Unwanted error " + result);
throw("Unwanted error" + JSON.stringify(result));
}

var result;
Expand Down
2 changes: 1 addition & 1 deletion test/mjsunit/test-allDbs.js
Expand Up @@ -2,7 +2,7 @@ include("mjsunit.js");
include("../../module/node-couch.js");

function unwantedError(result) {
throw new Exception("Unwanted error " + result);
throw("Unwanted error" + JSON.stringify(result));
}

var result;
Expand Down
2 changes: 1 addition & 1 deletion test/mjsunit/test-create-compact-info-drop.js
Expand Up @@ -2,7 +2,7 @@ include("mjsunit.js");
include("../../module/node-couch.js");

function unwantedError(result) {
throw new Exception("Unwanted error " + result);
throw("Unwanted error" + JSON.stringify(result));
}

var db;
Expand Down
2 changes: 1 addition & 1 deletion test/mjsunit/test-generateUUIDs.js
Expand Up @@ -2,7 +2,7 @@ include("mjsunit.js");
include("../../module/node-couch.js");

function unwantedError(result) {
throw new Exception("Unwanted error " + result);
throw("Unwanted error" + JSON.stringify(result));
}

var result = 0;
Expand Down

0 comments on commit 38ab66e

Please sign in to comment.