summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2010-02-05 01:13:28 +0000
committerJan Lehnardt <jan@apache.org>2010-02-05 01:13:28 +0000
commit15d10793a32a5fa57c80e9eab8803dc7d284ca6d (patch)
treeaf84bff66183ba71fda98cb1c53b97b720690fe2 /share
parentff1618779bc85d8f16d6aeebec461fad51b008c5 (diff)
add list()-API cmompatible API to _show. Symmetry FTW.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@906755 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share')
-rw-r--r--share/server/render.js14
-rw-r--r--share/www/script/test/show_documents.js33
2 files changed, 45 insertions, 2 deletions
diff --git a/share/server/render.js b/share/server/render.js
index 11c76373..1e341ec7 100644
--- a/share/server/render.js
+++ b/share/server/render.js
@@ -212,8 +212,20 @@ var Render = (function() {
function runShow(fun, ddoc, args) {
try {
+ resetList();
Mime.resetProvides();
- var resp = fun.apply(ddoc, args);
+ var resp = fun.apply(ddoc, args) || {};
+
+ // handle list() style API
+ if (chunks.length && chunks.length > 0) {
+ resp = maybeWrapResponse(resp);
+ resp.headers = resp.headers || {};
+ for(var header in startResp) {
+ resp.headers[header] = startResp[header]
+ }
+ resp.body = chunks.join("") + (resp.body || "");
+ resetList();
+ }
if (Mime.providesUsed) {
resp = Mime.runProvides(args[1]);
diff --git a/share/www/script/test/show_documents.js b/share/www/script/test/show_documents.js
index 2e895838..f49c1f1f 100644
--- a/share/www/script/test/show_documents.js
+++ b/share/www/script/test/show_documents.js
@@ -22,7 +22,6 @@ couchTests.show_documents = function(debug) {
shows: {
"hello" : stringFun(function(doc, req) {
log("hello fun");
- log(req);
if (doc) {
return "Hello World";
} else {
@@ -80,6 +79,25 @@ couchTests.show_documents = function(debug) {
"body" : "something"
}
}),
+ "list-api" : stringFun(function(doc, req) {
+ start({"X-Couch-Test-Header": "Yeah"});
+ send("Hey");
+ }),
+ "list-api-mix" : stringFun(function(doc, req) {
+ start({"X-Couch-Test-Header": "Yeah"});
+ send("Hey ");
+ return "Dude";
+ }),
+ "list-api-mix-with-header" : stringFun(function(doc, req) {
+ start({"X-Couch-Test-Header": "Yeah"});
+ send("Hey ");
+ return {
+ headers: {
+ "X-Couch-Test-Header-Awesome": "Oh Yeah!"
+ },
+ body: "Dude"
+ };
+ }),
"accept-switch" : stringFun(function(doc, req) {
if (req.headers["Accept"].match(/image/)) {
return {
@@ -362,5 +380,18 @@ couchTests.show_documents = function(debug) {
xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/hello/nonExistingDoc");
T(xhr.responseText == "New World");
+ // test list() compatible API
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/list-api/foo");
+ T(xhr.responseText == "Hey");
+ TEquals("Yeah", xhr.getResponseHeader("X-Couch-Test-Header"), "header should be cool");
+
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/list-api-mix/foo");
+ T(xhr.responseText == "Hey Dude");
+ TEquals("Yeah", xhr.getResponseHeader("X-Couch-Test-Header"), "header should be cool");
+
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/list-api-mix-with-header/foo");
+ T(xhr.responseText == "Hey Dude");
+ TEquals("Yeah", xhr.getResponseHeader("X-Couch-Test-Header"), "header should be cool");
+ TEquals("Oh Yeah!", xhr.getResponseHeader("X-Couch-Test-Header-Awesome"), "header should be cool");
};