You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ra...@apache.org on 2011/10/01 05:19:44 UTC

svn commit: r1177891 - in /couchdb/branches/1.2.x: THANKS share/www/script/test/update_documents.js src/couchdb/couch_httpd_show.erl

Author: randall
Date: Sat Oct  1 03:19:44 2011
New Revision: 1177891

URL: http://svn.apache.org/viewvc?rev=1177891&view=rev
Log:
fix COUCHDB-648 - _update handler ignores "code"

Test by Christian Carter
This is a backport of r1177890

Modified:
    couchdb/branches/1.2.x/THANKS
    couchdb/branches/1.2.x/share/www/script/test/update_documents.js
    couchdb/branches/1.2.x/src/couchdb/couch_httpd_show.erl

Modified: couchdb/branches/1.2.x/THANKS
URL: http://svn.apache.org/viewvc/couchdb/branches/1.2.x/THANKS?rev=1177891&r1=1177890&r2=1177891&view=diff
==============================================================================
--- couchdb/branches/1.2.x/THANKS (original)
+++ couchdb/branches/1.2.x/THANKS Sat Oct  1 03:19:44 2011
@@ -88,5 +88,6 @@ suggesting improvements or submitting ch
  * Trond Norbye <tr...@gmail.com>
  * Alexander Shorin <kx...@gmail.com>
  * Christopher Bonhage <qu...@me.com>
+ * Christian Carter <cd...@gmail.com>
 
 For a list of authors see the `AUTHORS` file.

Modified: couchdb/branches/1.2.x/share/www/script/test/update_documents.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.2.x/share/www/script/test/update_documents.js?rev=1177891&r1=1177890&r2=1177891&view=diff
==============================================================================
--- couchdb/branches/1.2.x/share/www/script/test/update_documents.js (original)
+++ couchdb/branches/1.2.x/share/www/script/test/update_documents.js Sat Oct  1 03:19:44 2011
@@ -75,6 +75,17 @@ couchTests.update_documents = function(d
        }),
        "get-uuid" : stringFun(function(doc, req) {
          return [null, req.uuid];
+       }),
+       "code-n-bump" : stringFun(function(doc,req) {
+         if (!doc.counter) doc.counter = 0;
+         doc.counter += 1;
+         var message = "<h1>bumped it!</h1>";
+         resp = {"code": 302, "body": message}
+         return [doc, resp];
+       }),
+       "resp-code" : stringFun(function(doc,req) {
+         resp = {"code": 302}
+         return [null, resp];
        })
     }
   };
@@ -179,4 +190,17 @@ couchTests.update_documents = function(d
 
   var doc = db.open("with/slash");
   TEquals(2, doc.counter, "counter should be 2");
+
+  // COUCHDB-648 - the code in the JSON response should be honored
+
+  xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/code-n-bump/"+docid, {
+    headers : {"X-Couch-Full-Commit":"true"}
+  });
+  T(xhr.status == 302);
+  T(xhr.responseText == "<h1>bumped it!</h1>");
+  doc = db.open(docid);
+  T(doc.counter == 3);
+
+  xhr = CouchDB.request("POST", "/test_suite_db/_design/update/_update/resp-code/");
+  T(xhr.status == 302);
 };

Modified: couchdb/branches/1.2.x/src/couchdb/couch_httpd_show.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.2.x/src/couchdb/couch_httpd_show.erl?rev=1177891&r1=1177890&r2=1177891&view=diff
==============================================================================
--- couchdb/branches/1.2.x/src/couchdb/couch_httpd_show.erl (original)
+++ couchdb/branches/1.2.x/src/couchdb/couch_httpd_show.erl Sat Oct  1 03:19:44 2011
@@ -127,7 +127,7 @@ handle_doc_update_req(Req, _Db, _DDoc) -
 send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) ->
     JsonReq = couch_httpd_external:json_req_obj(Req, Db, DocId),
     JsonDoc = couch_query_servers:json_doc(Doc),
-    {Code, JsonResp1} = case couch_query_servers:ddoc_prompt(DDoc,
+    JsonResp1 = case couch_query_servers:ddoc_prompt(DDoc,
                 [<<"updates">>, UpdateName], [JsonDoc, JsonReq]) of
         [<<"up">>, {NewJsonDoc}, {JsonResp}] ->
             Options = case couch_httpd:header_value(Req, "X-Couch-Full-Commit",
@@ -140,16 +140,14 @@ send_doc_update_response(Req, Db, DDoc, 
             NewDoc = couch_doc:from_json_obj({NewJsonDoc}),
             {ok, NewRev} = couch_db:update_doc(Db, NewDoc, Options),
             NewRevStr = couch_doc:rev_to_str(NewRev),
-            JsonRespWithRev =  {[{<<"headers">>,
-                {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]}} | JsonResp]},
-            {201, JsonRespWithRev};
-        [<<"up">>, _Other, JsonResp] ->
-            {200, JsonResp}
+            {[{<<"code">>, 201}, {<<"headers">>,
+                {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]}} | JsonResp]};
+        [<<"up">>, _Other, {JsonResp}] ->
+            {[{<<"code">>, 200} | JsonResp]}
     end,
-    
-    JsonResp2 = couch_util:json_apply_field({<<"code">>, Code}, JsonResp1),
+
     % todo set location field
-    couch_httpd_external:send_external_response(Req, JsonResp2).
+    couch_httpd_external:send_external_response(Req, JsonResp1).
 
 
 % view-list request with view and list from same design doc.