You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jc...@apache.org on 2009/06/07 08:05:32 UTC
svn commit: r782332 - in /couchdb/branches/list-iterator:
share/server/render.js share/www/script/test/list_views.js
src/couchdb/couch_httpd_show.erl
Author: jchris
Date: Sun Jun 7 06:05:32 2009
New Revision: 782332
URL: http://svn.apache.org/viewvc?rev=782332&view=rev
Log:
a few more tests pass, refactoring
Modified:
couchdb/branches/list-iterator/share/server/render.js
couchdb/branches/list-iterator/share/www/script/test/list_views.js
couchdb/branches/list-iterator/src/couchdb/couch_httpd_show.erl
Modified: couchdb/branches/list-iterator/share/server/render.js
URL: http://svn.apache.org/viewvc/couchdb/branches/list-iterator/share/server/render.js?rev=782332&r1=782331&r2=782332&view=diff
==============================================================================
--- couchdb/branches/list-iterator/share/server/render.js (original)
+++ couchdb/branches/list-iterator/share/server/render.js Sun Jun 7 06:05:32 2009
@@ -112,7 +112,7 @@
return publicMethods;
})();
-
+var respCT;
// this function provides a shortcut for managing responses by Accept header
respondWith = function(req, responders) {
var bestKey = null, accept = req.headers["Accept"];
@@ -129,11 +129,14 @@
bestKey = req.query.format;
}
var rFunc = responders[bestKey || responders.fallback || "html"];
- if (rFunc) {
- var resp = maybeWrapResponse(rFunc());
- resp["headers"] = resp["headers"] || {};
- resp["headers"]["Content-Type"] = bestMime;
- respond(["resp", resp]);
+ respCT = bestMime;
+ if (rFunc) {
+ if (isShow) {
+ var resp = maybeWrapResponse(rFunc());
+ resp["headers"] = resp["headers"] || {};
+ resp["headers"]["Content-Type"] = bestMime;
+ respond(["resp", resp]);
+ }
} else {
throw({code:406, body:"Not Acceptable: "+accept});
}
@@ -234,16 +237,18 @@
////
////
////
-
+var isShow = false;
var Render = (function() {
var row_info;
return {
show : function(funSrc, doc, req) {
+ isShow = true;
var formFun = compileFunction(funSrc);
runShowRenderFunction(formFun, [doc, req], funSrc, true);
},
list : function(head, req) {
+ isShow = false;
runListRenderFunction(funs[0], [head, req], funsrc[0]);
}
}
Modified: couchdb/branches/list-iterator/share/www/script/test/list_views.js
URL: http://svn.apache.org/viewvc/couchdb/branches/list-iterator/share/www/script/test/list_views.js?rev=782332&r1=782331&r2=782332&view=diff
==============================================================================
--- couchdb/branches/list-iterator/share/www/script/test/list_views.js (original)
+++ couchdb/branches/list-iterator/share/www/script/test/list_views.js Sun Jun 7 06:05:32 2009
@@ -113,8 +113,8 @@
}
});
}),
- qsParams: stringFun(function(req) {
- return req.query.foo + "\n";
+ qsParams: stringFun(function(head, req) {
+ return toJSON(req.query) + "\n";
}),
stopIter: stringFun(function(req) {
send("head");
@@ -126,7 +126,7 @@
};
return " tail";
}),
- stopIter2: stringFun(function(req) {
+ stopIter2: stringFun(function(head, req) {
respondWith(req, {
html: function() {
send("head");
@@ -153,9 +153,9 @@
return "after row: "+toJSON(row);
}),
emptyList: stringFun(function() {
- return "";
+ return " ";
}),
- rowError : stringFun(function(head, row, req, row_info) {
+ rowError : stringFun(function(head, req) {
send("head");
var row = getRow();
send(fooBarBam); // intentional error
@@ -263,22 +263,6 @@
return;
- // now with extra qs params
- var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/qsParams/basicView?foo=blam");
- T(xhr.responseText.match(/blam/));
-
- var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter/basicView");
- T("content type" == "text/plain");
- T(xhr.responseText.match(/^head 0 1 2 tail$/) && "basic stop");
- xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter2/basicView");
- T(xhr.responseText.match(/^head 0 1 2 tail$/) && "stop 2");
-
- // aborting iteration with reduce
- var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter/withReduce?group=true");
- T(xhr.responseText.match(/^head 0 1 2 tail$/) && "reduce stop");
- xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter2/withReduce?group=true");
- T(xhr.responseText.match(/^head 0 1 2 tail$/) && "reduce stop 2");
-
// empty list
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/emptyList/basicView");
T(xhr.responseText.match(/^$/));
@@ -305,6 +289,26 @@
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/rowError/basicView");
T(/<h1>Render Error<\/h1>/.test(xhr.responseText));
+
+ // now with extra qs params
+ var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/qsParams/basicView?foo=blam");
+ T(xhr.responseText.match(/blam/));
+
+ var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter/basicView");
+ T("content type" == "text/plain");
+ T(xhr.responseText.match(/^head 0 1 2 tail$/) && "basic stop");
+
+ return;
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter2/basicView");
+ T(xhr.responseText.match(/^head 0 1 2 tail$/) && "stop 2");
+
+ // aborting iteration with reduce
+ var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter/withReduce?group=true");
+ T(xhr.responseText.match(/^head 0 1 2 tail$/) && "reduce stop");
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter2/withReduce?group=true");
+ T(xhr.responseText.match(/^head 0 1 2 tail$/) && "reduce stop 2");
+
+
// with accept headers for HTML
Modified: couchdb/branches/list-iterator/src/couchdb/couch_httpd_show.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/list-iterator/src/couchdb/couch_httpd_show.erl?rev=782332&r1=782331&r2=782332&view=diff
==============================================================================
--- couchdb/branches/list-iterator/src/couchdb/couch_httpd_show.erl (original)
+++ couchdb/branches/list-iterator/src/couchdb/couch_httpd_show.erl Sun Jun 7 06:05:32 2009
@@ -135,12 +135,16 @@
make_map_send_row_fun(QueryServer, Req) ->
fun(Resp, Db2, {{Key, DocId}, Value}, _IncludeDocs, RowFront) ->
try
- [<<"chunks">>,Chunks] = couch_query_servers:render_list_row(QueryServer,
+ [Go,Chunks] = couch_query_servers:render_list_row(QueryServer,
Req, Db2, {{Key, DocId}, Value}),
Chunk = RowFront ++ ?b2l(?l2b(Chunks)),
send_non_empty_chunk(Resp, Chunk),
- % {stop, ""};
- {ok, ""}
+ case Go of
+ <<"chunks">> ->
+ {ok, ""};
+ <<"end">> ->
+ {stop, ""}
+ end
catch
throw:Error ->
send_chunked_error(Resp, Error),