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

git commit: Prefer stringFun() over toString() and add binary test to update functions.

Updated Branches:
  refs/heads/master 84dea02aa -> f94530da9


Prefer stringFun() over toString() and add binary test to update functions.

Closes COUCHDB-626

Patch by Brian Candler.


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/f94530da
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/f94530da
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/f94530da

Branch: refs/heads/master
Commit: f94530da90a4ea9b60185b57c2a35b923ecf3fa1
Parents: 84dea02
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sun Oct 30 17:04:39 2011 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Sun Oct 30 17:04:39 2011 +0100

----------------------------------------------------------------------
 share/www/script/test/security_validation.js |    4 ++--
 share/www/script/test/show_documents.js      |    4 ++--
 share/www/script/test/update_documents.js    |   18 ++++++++++++++++++
 3 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/f94530da/share/www/script/test/security_validation.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/security_validation.js b/share/www/script/test/security_validation.js
index 42aa11c..862924a 100644
--- a/share/www/script/test/security_validation.js
+++ b/share/www/script/test/security_validation.js
@@ -69,7 +69,7 @@ couchTests.security_validation = function(debug) {
       var designDoc = {
         _id:"_design/test",
         language: "javascript",
-        validate_doc_update: "(" + (function (newDoc, oldDoc, userCtx, secObj) {
+        validate_doc_update: stringFun(function (newDoc, oldDoc, userCtx, secObj) {
           if (secObj.admin_override) {
             if (userCtx.roles.indexOf('_admin') != -1) {
               // user is admin, they can do anything
@@ -85,7 +85,7 @@ couchTests.security_validation = function(debug) {
               throw {unauthorized:
                   "You are not the author of this document. You jerk."};
           }
-        }).toString() + ")"
+        })
       }
 
       // Save a document normally

http://git-wip-us.apache.org/repos/asf/couchdb/blob/f94530da/share/www/script/test/show_documents.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/show_documents.js b/share/www/script/test/show_documents.js
index cf73ed5..3c4b43a 100644
--- a/share/www/script/test/show_documents.js
+++ b/share/www/script/test/show_documents.js
@@ -318,11 +318,11 @@ couchTests.show_documents = function(debug) {
   T(xhr.status != 304, "changed ddoc");
 
   // update design doc function
-  designDoc.shows["just-name"] = (function(doc, req) {
+  designDoc.shows["just-name"] = stringFun(function(doc, req) {
    return {
      body : "Just old " + doc.name
    };
-  }).toString();
+  });
   T(db.save(designDoc).ok);
 
   xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/just-name/"+docid, {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/f94530da/share/www/script/test/update_documents.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/update_documents.js b/share/www/script/test/update_documents.js
index 59af459..b352bb4 100644
--- a/share/www/script/test/update_documents.js
+++ b/share/www/script/test/update_documents.js
@@ -86,6 +86,15 @@ couchTests.update_documents = function(debug) {
        "resp-code" : stringFun(function(doc,req) {
          resp = {"code": 302}
          return [null, resp];
+       }),
+       "binary" : stringFun(function(doc, req) {
+         var resp = {
+           "headers" : {
+             "Content-Type" : "application/octet-stream"
+           },
+           "base64" : "aGVsbG8gd29ybGQh" // "hello world!" encoded
+         };
+         return [doc, resp];
        })
     }
   };
@@ -203,4 +212,13 @@ couchTests.update_documents = function(debug) {
 
   xhr = CouchDB.request("POST", "/test_suite_db/_design/update/_update/resp-code/");
   T(xhr.status == 302);
+
+  // base64 response
+  xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/binary/"+docid, {
+    headers : {"X-Couch-Full-Commit":"false"},
+    body    : 'rubbish'
+  });
+  T(xhr.status == 201);
+  T(xhr.responseText == "hello world!");
+  T(/application\/octet-stream/.test(xhr.getResponseHeader("Content-Type")));
 };