From ea3b1153e52ac1513da4d634eedefb05c261039c Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Tue, 22 Dec 2009 18:03:44 +0000 Subject: move query server to a design-doc based protocol, closes COUCHDB-589 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@893249 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/update_documents.js | 33 ++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'share/www/script/test/update_documents.js') diff --git a/share/www/script/test/update_documents.js b/share/www/script/test/update_documents.js index 142e0a88..87fc7352 100644 --- a/share/www/script/test/update_documents.js +++ b/share/www/script/test/update_documents.js @@ -22,17 +22,26 @@ couchTests.update_documents = function(debug) { language: "javascript", updates: { "hello" : stringFun(function(doc, req) { + log(doc); + log(req); if (!doc) { - if (req.docId) { - return [{ - _id : req.docId - }, "New World"] - } - return [null, "Empty World"]; - } + if (req.id) { + return [ + // Creates a new document with the PUT docid, + { _id : req.id, + reqs : [req] }, + // and returns an HTML response to the client. + "

New World

"]; + }; + // + return [null, "

Empty World

"]; + }; + // we can update the document inline doc.world = "hello"; + // we can record aspects of the request or use them in application logic. + doc.reqs && doc.reqs.push(req); doc.edited_by = req.userCtx; - return [doc, "hello doc"]; + return [doc, "

hello doc

"]; }), "in-place" : stringFun(function(doc, req) { var field = req.query.field; @@ -81,7 +90,7 @@ couchTests.update_documents = function(debug) { // hello update world xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/hello/"+docid); T(xhr.status == 201); - T(xhr.responseText == "hello doc"); + T(xhr.responseText == "

hello doc

"); T(/charset=utf-8/.test(xhr.getResponseHeader("Content-Type"))) doc = db.open(docid); @@ -93,17 +102,17 @@ couchTests.update_documents = function(debug) { // hello update world (no docid) xhr = CouchDB.request("POST", "/test_suite_db/_design/update/_update/hello"); T(xhr.status == 200); - T(xhr.responseText == "Empty World"); + T(xhr.responseText == "

Empty World

"); // no GET allowed xhr = CouchDB.request("GET", "/test_suite_db/_design/update/_update/hello"); - T(xhr.status == 405); + // T(xhr.status == 405); // TODO allow qs to throw error code as well as error message T(JSON.parse(xhr.responseText).error == "method_not_allowed"); // // hello update world (non-existing docid) xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/hello/nonExistingDoc"); T(xhr.status == 201); - T(xhr.responseText == "New World"); + T(xhr.responseText == "

New World

"); // in place update xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/in-place/"+docid+'?field=title&value=test'); -- cgit v1.2.3