diff options
author | Jan Lehnardt <jan@apache.org> | 2013-03-30 22:34:57 +0100 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2013-03-30 22:34:57 +0100 |
commit | 97505126c90469e7588272d0eec451b93159cd9a (patch) | |
tree | 09643d5a0a9ffb5d2b246de6d1fb1d1dc2ccff73 | |
parent | 5fa09a38ea96695058b4c26d3160615d19b1579d (diff) | |
parent | 83593ac45d056e07223aaca82d3b16cb46ab8e2e (diff) | |
download | couchdb-97505126c90469e7588272d0eec451b93159cd9a.tar.gz |
Merge branch 'various-tests' of https://github.com/jo/couchdb
* 'various-tests' of https://github.com/jo/couchdb:
Test form-urlencoded doc update
Test attachment upload via multipart/form-data
Closes PR #55
-rw-r--r-- | share/www/script/test/attachments.js | 27 | ||||
-rw-r--r-- | share/www/script/test/update_documents.js | 18 |
2 files changed, 45 insertions, 0 deletions
diff --git a/share/www/script/test/attachments.js b/share/www/script/test/attachments.js index db4524a92..2fa08ee25 100644 --- a/share/www/script/test/attachments.js +++ b/share/www/script/test/attachments.js @@ -298,4 +298,31 @@ couchTests.attachments= function(debug) { var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc7/attachment.txt"); TEquals('MntvB0NYESObxH4VRDUycw==', xhr.getResponseHeader("Content-MD5")); + // test attachment via multipart/form-data + var bin_doc8 = { + _id: "bin_doc8" + }; + T(db.save(bin_doc8).ok); + var doc = db.open("bin_doc8"); + var body = "------TF\r\n" + + "Content-Disposition: form-data; name=\"_rev\"\r\n\r\n" + + doc._rev + "\r\n" + + "------TF\r\n" + + "Content-Disposition: form-data; name=\"_attachments\"; filename=\"file.txt\"\r\n" + + "Content-Type: text/plain\r\n\r\n" + + "contents of file.txt\r\n\r\n" + + "------TF--" + xhr = CouchDB.request("POST", "/test_suite_db/bin_doc8", { + headers: { + "Content-Type": "multipart/form-data; boundary=----TF", + "Content-Length": body.length + }, + body: body + }); + TEquals(201, xhr.status); + TEquals(true, JSON.parse(xhr.responseText).ok); + var doc = db.open("bin_doc8"); + T(doc._attachments); + T(doc._attachments['file.txt']); + }; diff --git a/share/www/script/test/update_documents.js b/share/www/script/test/update_documents.js index 32ec72e74..868421770 100644 --- a/share/www/script/test/update_documents.js +++ b/share/www/script/test/update_documents.js @@ -50,6 +50,13 @@ couchTests.update_documents = function(debug) { doc[field] = value; return [doc, message]; }), + "form-update" : stringFun(function(doc, req) { + for (var field in req.form) { + doc[field] = req.form[field]; + } + var message = "updated doc from form"; + return [doc, message]; + }), "bump-counter" : stringFun(function(doc, req) { if (!doc.counter) doc.counter = 0; doc.counter += 1; @@ -156,6 +163,17 @@ couchTests.update_documents = function(debug) { doc = db.open(docid); T(doc.title == "test"); + // form update via application/x-www-form-urlencoded + xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/form-update/"+docid, { + headers : {"Content-Type":"application/x-www-form-urlencoded"}, + body : "formfoo=bar&formbar=foo" + }); + TEquals(201, xhr.status); + TEquals("updated doc from form", xhr.responseText); + doc = db.open(docid); + TEquals("bar", doc.formfoo); + TEquals("foo", doc.formbar); + // bump counter xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/bump-counter/"+docid, { headers : {"X-Couch-Full-Commit":"true"} |