couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rand...@apache.org
Subject svn commit: r1177890 - in /couchdb/trunk: THANKS share/www/script/test/update_documents.js src/couch_mrview/src/couch_mrview_show.erl
Date Sat, 01 Oct 2011 03:19:06 GMT
Author: randall
Date: Sat Oct  1 03:19:05 2011
New Revision: 1177890

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

Test by Christian Carter

Modified:
    couchdb/trunk/THANKS
    couchdb/trunk/share/www/script/test/update_documents.js
    couchdb/trunk/src/couch_mrview/src/couch_mrview_show.erl

Modified: couchdb/trunk/THANKS
URL: http://svn.apache.org/viewvc/couchdb/trunk/THANKS?rev=1177890&r1=1177889&r2=1177890&view=diff
==============================================================================
--- couchdb/trunk/THANKS (original)
+++ couchdb/trunk/THANKS Sat Oct  1 03:19:05 2011
@@ -88,5 +88,6 @@ suggesting improvements or submitting ch
  * Trond Norbye <trond.norbye@gmail.com>
  * Alexander Shorin <kxepal@gmail.com>
  * Christopher Bonhage <queezey@me.com>
+ * Christian Carter <cdcarter@gmail.com>
 
 For a list of authors see the `AUTHORS` file.

Modified: couchdb/trunk/share/www/script/test/update_documents.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/update_documents.js?rev=1177890&r1=1177889&r2=1177890&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/update_documents.js (original)
+++ couchdb/trunk/share/www/script/test/update_documents.js Sat Oct  1 03:19:05 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/trunk/src/couch_mrview/src/couch_mrview_show.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couch_mrview/src/couch_mrview_show.erl?rev=1177890&r1=1177889&r2=1177890&view=diff
==============================================================================
--- couchdb/trunk/src/couch_mrview/src/couch_mrview_show.erl (original)
+++ couchdb/trunk/src/couch_mrview/src/couch_mrview_show.erl Sat Oct  1 03:19:05 2011
@@ -131,7 +131,7 @@ send_doc_update_response(Req, Db, DDoc, 
     JsonDoc = couch_query_servers:json_doc(Doc),
     Cmd = [<<"updates">>, UpdateName],
     UpdateResp = couch_query_servers:ddoc_prompt(DDoc, Cmd, [JsonDoc, JsonReq]),
-    {Code, JsonResp} = case UpdateResp of
+    JsonResp = case UpdateResp of
         [<<"up">>, {NewJsonDoc}, {JsonResp0}] ->
             case couch_httpd:header_value(
                     Req, "X-Couch-Full-Commit", "false") of
@@ -143,15 +143,15 @@ 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),
-            JsonHeaders = {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]},
-            JsonRespWithRev = {[{<<"headers">>, JsonHeaders} | JsonResp0]},
-            {201, JsonRespWithRev};
-        [<<"up">>, _Other, JsonResp0] ->
-            {200, JsonResp0}
+            {[
+                {<<"code">>, 201},
+                {<<"headers">>, {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]}}
+                | JsonResp0]};
+        [<<"up">>, _Other, {JsonResp0}] ->
+            {[{<<"code">>, 200} | JsonResp0]}
     end,
-    JsonResp2 = json_apply_field({<<"code">>, Code}, JsonResp),
     % todo set location field
-    couch_httpd_external:send_external_response(Req, JsonResp2).
+    couch_httpd_external:send_external_response(Req, JsonResp).
 
 
 handle_view_list_req(#httpd{method='GET'}=Req, Db, DDoc) ->



Mime
View raw message