Skip to content

Commit

Permalink
Test form-urlencoded doc update
Browse files Browse the repository at this point in the history
Update handlers have access to a form object parsed from an
application/x-www-form-urlencoded request.
  • Loading branch information
jo committed Mar 27, 2013
1 parent fe2dca0 commit 83593ac
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions share/www/script/test/update_documents.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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"}
Expand Down

0 comments on commit 83593ac

Please sign in to comment.