couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r804555 - in /couchdb/trunk: share/www/script/test/basics.js src/couchdb/couch_httpd_db.erl
Date Sun, 16 Aug 2009 03:07:21 GMT
Author: davisp
Date: Sun Aug 16 03:07:21 2009
New Revision: 804555

URL: http://svn.apache.org/viewvc?rev=804555&view=rev
Log:
Make POST's reflect a provided _id member.

Fixes COUCHDB-468


Modified:
    couchdb/trunk/share/www/script/test/basics.js
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/share/www/script/test/basics.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/basics.js?rev=804555&r1=804554&r2=804555&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/basics.js (original)
+++ couchdb/trunk/share/www/script/test/basics.js Sun Aug 16 03:07:21 2009
@@ -161,6 +161,16 @@
   T(locs[4] == resp.id);
   T(locs[3] == "test_suite_db");
 
+  // test that that POST's with an _id aren't overriden with a UUID.
+  var xhr = CouchDB.request("POST", "/test_suite_db", {
+    body: JSON.stringify({"_id": "oppossum", "yar": "matey"})
+  });
+  var resp = JSON.parse(xhr.responseText);
+  T(resp.ok);
+  T(resp.id == "oppossum");
+  var doc = db.open("oppossum");
+  T(doc.yar == "matey");
+
   // document put's should return a Location header
   var xhr = CouchDB.request("PUT", "/test_suite_db/newdoc", {
     body: JSON.stringify({"a":1})

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=804555&r1=804554&r2=804555&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Sun Aug 16 03:07:21 2009
@@ -271,21 +271,27 @@
 
 db_req(#httpd{method='POST',path_parts=[DbName]}=Req, Db) ->
     Doc = couch_doc:from_json_obj(couch_httpd:json_body(Req)),
-    DocId = couch_util:new_uuid(),
+    Doc2 = case Doc#doc.id of
+        <<"">> ->
+            Doc#doc{id=couch_util:new_uuid(), revs={0, []}};
+        _ ->
+            Doc
+    end,
+    DocId = Doc2#doc.id,
     case couch_httpd:qs_value(Req, "batch") of
     "ok" ->
         % batch
-        ok = couch_batch_save:eventually_save_doc(Db#db.name,
-                Doc#doc{id=DocId}, Db#db.user_ctx),
+        ok = couch_batch_save:eventually_save_doc(
+            Db#db.name, Doc2, Db#db.user_ctx),
         send_json(Req, 202, [], {[
             {ok, true},
             {id, DocId}
         ]});
     _Normal ->
         % normal
-        {ok, NewRev} = couch_db:update_doc(Db, Doc#doc{id=DocId}, []),
-        DocUrl = absolute_uri(Req,
-            binary_to_list(<<"/",DbName/binary,"/",DocId/binary>>)),
+        {ok, NewRev} = couch_db:update_doc(Db, Doc2, []),
+        DocUrl = absolute_uri(
+            Req, binary_to_list(<<"/",DbName/binary,"/", DocId/binary>>)),
         send_json(Req, 201, [{"Location", DocUrl}], {[
             {ok, true},
             {id, DocId},



Mime
View raw message