couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r677682 - in /incubator/couchdb/trunk: share/www/script/couch_tests.js src/couchdb/couch_db.erl
Date Thu, 17 Jul 2008 18:52:46 GMT
Author: jan
Date: Thu Jul 17 11:52:46 2008
New Revision: 677682

URL: http://svn.apache.org/viewvc?rev=677682&view=rev
Log:
Allow for empty attachments.

Modified:
    incubator/couchdb/trunk/share/www/script/couch_tests.js
    incubator/couchdb/trunk/src/couchdb/couch_db.erl

Modified: incubator/couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/couch_tests.js?rev=677682&r1=677681&r2=677682&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] Thu Jul 17 11:52:46 2008
@@ -558,7 +558,25 @@
     var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt");
     T(xhr.responseText == "This is a base64 encoded text");
     T(xhr.getResponseHeader("Content-Type") == "text/plain");
-    
+
+
+    // empty attachment
+    var binAttDoc2 = {
+      _id: "bin_doc5",
+      _attachments:{
+        "foo.txt": {
+          content_type:"text/plain",
+          data: ""
+        }
+      }
+    }
+
+    T(db.save(binAttDoc2).ok);
+
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc5/foo.txt");
+    T(xhr.responseText.length == 0);
+    T(xhr.getResponseHeader("Content-Type") == "text/plain");
+       
     // test RESTful doc API
     
     var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc2/foo2.txt", {
@@ -620,6 +638,30 @@
     
     var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc3/attachment.txt?rev=" + rev);
     T(xhr.status == 404);
+
+    // empty attachments
+    var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc4/attachment.txt", {
+      headers:{"Content-Type":"text/plain;charset=utf-8"},
+      body:""
+    });
+    T(xhr.status == 201);
+    var rev = JSON.parse(xhr.responseText).rev;
+
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc4/attachment.txt");
+    T(xhr.status == 200);
+    T(xhr.responseText.length == 0);
+    
+    // overwrite previsously empty attachment
+    var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc4/attachment.txt?rev=" + rev,
{
+      headers:{"Content-Type":"text/plain;charset=utf-8"},
+      body:"This is a string"
+    });
+    T(xhr.status == 201);
+
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc4/attachment.txt");
+    T(xhr.status == 200);
+    T(xhr.responseText == "This is a string");
+    
   },
 
   content_negotiation: function(debug) {

Modified: incubator/couchdb/trunk/src/couchdb/couch_db.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_db.erl?rev=677682&r1=677681&r2=677682&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_db.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_db.erl Thu Jul 17 11:52:46 2008
@@ -367,7 +367,7 @@
                     end,
                     {{0,0}, 0}),
                 {Fd, NewStreamPointer, Len};
-            Bin when is_binary(Bin), size(Bin) > 0 ->
+            Bin when is_binary(Bin) ->
                 {ok, StreamPointer} = couch_stream:write(OutputStream, Bin),
                 {Fd, StreamPointer, size(Bin)}
             end,



Mime
View raw message