From 36bbc72b6b0992639a0ba7a2077d75ec9f7cf03d Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Tue, 11 Aug 2009 18:50:08 +0000 Subject: Initial commit of _update handler. Thanks to Paul Davis, Jason Davies for code and others for discussion. The _update handler accepts POSTs to paths like: /db/_design/foo/_update/bar and PUTs which include docids, like: /db/_design/foo/_update/bar/docid The function signature: function(doc, req) { doc.a_new_field = req.query.something; return [doc, "

added something to your doc

"]; } The tests in update_documents.js are fairly complete and include examples of bumping a counter, changing only a single field, parsing from (and returning) XML, and creating new documents. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@803245 13f79535-47bb-0310-9956-ffa450edef68 --- test/query_server_spec.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/query_server_spec.rb b/test/query_server_spec.rb index dfc57a5b..c9fb6942 100644 --- a/test/query_server_spec.rb +++ b/test/query_server_spec.rb @@ -242,12 +242,21 @@ functions = { }, "filter-basic" => { "js" => <<-JS - function(doc, req, userCtx) { + function(doc, req) { if (doc.good) { return true; } } JS + }, + "update-basic" => { + "js" => <<-JS + function(doc, req) { + doc.world = "hello"; + var resp = [doc, "hello doc"]; + return resp; + } + JS } } @@ -441,6 +450,19 @@ describe "query server normal case" do should == [true, [true, false, true]] end end + + describe "update" do + before(:all) do + @fun = functions["update-basic"][LANGUAGE] + @qs.reset! + end + it "should return a doc and a resp body" do + up, doc, resp = @qs.run(["update", @fun, {"foo" => "gnarly"}, {"verb" => "POST"}]) + up.should == "up" + doc.should == {"foo" => "gnarly", "world" => "hello"} + resp["body"].should == "hello doc" + end + end end def should_have_exited qs -- cgit v1.2.3