Skip to content

Commit

Permalink
Fixed bug causing getDesignDoc to fail.
Browse files Browse the repository at this point in the history
Fixed issue where the body was not returned from http requests
for views, updated test and fixed a couple missing semicolons.

Change-Id: Ib0ee4f355d3f4237405d2fe9945a7ffd4c13c3f0
Reviewed-on: http://review.couchbase.org/28989
Tested-by: Brett Lawson <brett19@gmail.com>
Reviewed-by: Mark Nunberg <mnunberg@haskalah.org>
  • Loading branch information
brett19 authored and mnunberg committed Sep 16, 2013
1 parent fac5ad6 commit 568f036
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var CONST;

module.exports._init = function(c) {
CONST = c;
}
};

function makeRestHandler(innerCallback) {

Expand All @@ -17,7 +17,7 @@ function makeRestHandler(innerCallback) {
}

try {
body = JSON.parse(response.data)
body = JSON.parse(response.data);
} catch (parseError) {
// Error talking to server, pass the error on for now
innerCallback(parseError, null);
Expand Down Expand Up @@ -53,6 +53,8 @@ function makeRestHandler(innerCallback) {
innerCallback(errObj, body.rows);
} else if (body.results) {
innerCallback(errObj, body.results);
} else if (body.views) {
innerCallback(errObj, body);
} else {
innerCallback(errObj, null);
}
Expand All @@ -63,7 +65,7 @@ function makeRestHandler(innerCallback) {
module.exports.view = function(cb, ddoc, name, query) {
var query = query == undefined ? {} : query;
return new viewQuery.ViewQuery(cb, ddoc, name, query, makeRestHandler);
}
};


function makeDoc(doc) {
Expand All @@ -82,20 +84,20 @@ module.exports.setDesignDoc = function(cb, name, data, callback) {
content_type: "application/json",
lcb_http_type: CONST.LCB_HTTP_TYPE_VIEW
}, makeRestHandler(callback));
}
};

module.exports.getDesignDoc = function(cb, name, callback) {
cb.httpRequest(null, {
path: "_design/" + name,
method: CONST.LCB_HTTP_METHOD_GET,
lcb_http_type: CONST.LCB_HTTP_TYPE_VIEW
}, makeRestHandler(callback));
}
};

module.exports.removeDesignDoc = function(cb, name, callback) {
cb.httpRequest(null, {
path: "_design/" + name,
method: CONST.LCB_HTTP_METHOD_DELETE,
lcb_http_type: CONST.LCB_HTTP_TYPE_VIEW
}, makeRestHandler(callback));
}
};
8 changes: 6 additions & 2 deletions test/designdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ describe('#design documents', function() {
cb.removeDesignDoc(docname, function() {
// Ok, the design document should be done
cb.setDesignDoc(docname, ddoc, function(err, data) {
var util=require("util");
assert(!err, "error creating design document");
cb.getDesignDoc(docname, function(err, data) {
assert(!err, "error getting design document");
assert.deepEqual(data, ddoc);
cb.removeDesignDoc(docname, function(err, data) {
assert(!err, "Failed deleting design document");
done();
cb.getDesignDoc(docname, function(err, data) {
assert.ok(err.message.match(/not_found/));
assert.strictEqual(data, null);
done();
});
});
});
});
Expand Down

0 comments on commit 568f036

Please sign in to comment.