couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1166625 - in /couchdb/branches/1.1.x: THANKS share/server/render.js share/www/script/test/show_documents.js
Date Thu, 08 Sep 2011 11:03:20 GMT
Author: jan
Date: Thu Sep  8 11:03:20 2011
New Revision: 1166625

URL: http://svn.apache.org/viewvc?rev=1166625&view=rev
Log:
Fix list-style send() API in show functions when using provides()

Also fix ignoring the return value when the send() API isnused.

Patch by Alexander Shorin.

Closes COUCHDB-1272

Modified:
    couchdb/branches/1.1.x/THANKS
    couchdb/branches/1.1.x/share/server/render.js
    couchdb/branches/1.1.x/share/www/script/test/show_documents.js

Modified: couchdb/branches/1.1.x/THANKS
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/THANKS?rev=1166625&r1=1166624&r2=1166625&view=diff
==============================================================================
--- couchdb/branches/1.1.x/THANKS (original)
+++ couchdb/branches/1.1.x/THANKS Thu Sep  8 11:03:20 2011
@@ -80,6 +80,6 @@ suggesting improvements or submitting ch
  * Sam Bisbee <sam@sbisbee.com>
  * Nathan Vander Wilt <natevw@yahoo.com>
  * Caolan McMahon <caolan.mcmahon@googlemail.com>
- 
+ * Alexander Shorin <kxepal@gmail.com>
 
 For a list of authors see the `AUTHORS` file.

Modified: couchdb/branches/1.1.x/share/server/render.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/server/render.js?rev=1166625&r1=1166624&r2=1166625&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/server/render.js (original)
+++ couchdb/branches/1.1.x/share/server/render.js Thu Sep  8 11:03:20 2011
@@ -220,10 +220,10 @@ var Render = (function() {
       resetList();
       Mime.resetProvides();
       var resp = fun.apply(ddoc, args) || {};
+      resp = maybeWrapResponse(resp);
 
       // 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]
@@ -233,8 +233,12 @@ var Render = (function() {
       }
 
       if (Mime.providesUsed) {
-        resp = Mime.runProvides(args[1], ddoc);
-        resp = applyContentType(maybeWrapResponse(resp), Mime.responseContentType);
+        var provided_resp = Mime.runProvides(args[1], ddoc) || {};
+        provided_resp = maybeWrapResponse(provided_resp);
+        resp.body = (resp.body || "") + chunks.join("");
+        resp.body += provided_resp.body || "";
+        resp = applyContentType(resp, Mime.responseContentType);
+        resetList();
       }
 
       var type = typeOf(resp);

Modified: couchdb/branches/1.1.x/share/www/script/test/show_documents.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/script/test/show_documents.js?rev=1166625&r1=1166624&r2=1166625&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/www/script/test/show_documents.js (original)
+++ couchdb/branches/1.1.x/share/www/script/test/show_documents.js Thu Sep  8 11:03:20 2011
@@ -90,6 +90,24 @@ couchTests.show_documents = function(deb
         start({"X-Couch-Test-Header": "Yeah"});
         send("Hey");
       }),
+      "list-api-provides" : stringFun(function(doc, req) {
+        provides("text", function(){
+            send("foo, ");
+            send("bar, ");
+            send("baz!");
+        })
+      }),
+      "list-api-provides-and-return" : stringFun(function(doc, req) {
+        provides("text", function(){
+            send("4, ");
+            send("5, ");
+            send("6, ");
+            return "7!";
+        })
+        send("1, ");
+        send("2, ");
+        return "3, ";
+      }),
       "list-api-mix" : stringFun(function(doc, req) {
         start({"X-Couch-Test-Header": "Yeah"});
         send("Hey ");
@@ -395,6 +413,14 @@ couchTests.show_documents = function(deb
   T(xhr.responseText == "Hey");
   TEquals("Yeah", xhr.getResponseHeader("X-Couch-Test-Header"), "header should be cool");
 
+  // test list() compatible API with provides function
+  xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/list-api-provides/foo?format=text");
+  TEquals(xhr.responseText, "foo, bar, baz!", "should join chunks to response body");
+
+  // should keep next result order: chunks + return value + provided chunks + provided return
value
+  xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/list-api-provides-and-return/foo?format=text");
+  TEquals(xhr.responseText, "1, 2, 3, 4, 5, 6, 7!", "should not break 1..7 range");
+
   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");



Mime
View raw message