summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/chttpd/src/chttpd_show.erl11
-rw-r--r--test/elixir/test/update_documents_test.exs19
2 files changed, 21 insertions, 9 deletions
diff --git a/src/chttpd/src/chttpd_show.erl b/src/chttpd/src/chttpd_show.erl
index c2c37c66d..de1eb2805 100644
--- a/src/chttpd/src/chttpd_show.erl
+++ b/src/chttpd/src/chttpd_show.erl
@@ -95,11 +95,12 @@ show_etag(#httpd{user_ctx=UserCtx}=Req, Doc, DDoc, More) ->
couch_httpd:make_etag({couch_httpd:doc_etag(DDoc), DocPart, Accept,
UserCtx#user_ctx.roles, More}).
-% /db/_design/foo/update/bar/docid
-% updates a doc based on a request
-% handle_doc_update_req(#httpd{method = 'GET'}=Req, _Db, _DDoc) ->
-% % anything but GET
-% send_method_not_allowed(Req, "POST,PUT,DELETE,ETC");
+
+handle_doc_update_req(#httpd{
+ method=Method,
+ path_parts=[_, <<"_design">>, _, <<"_update">> | _MaybeDocIdParts]
+ }=Req, _Db, _DDoc) when Method =/= 'POST' andalso Method =/= 'PUT' ->
+ chttpd:send_method_not_allowed(Req, "POST,PUT");
handle_doc_update_req(#httpd{
path_parts=[_, _, _, _, UpdateName]
diff --git a/test/elixir/test/update_documents_test.exs b/test/elixir/test/update_documents_test.exs
index c29b31a4d..df5856b44 100644
--- a/test/elixir/test/update_documents_test.exs
+++ b/test/elixir/test/update_documents_test.exs
@@ -106,6 +106,17 @@ defmodule UpdateDocumentsTest do
@document %{word: "plankton", name: "Rusty"}
@tag :with_db
+ test "update error method not allowed", context do
+ db_name = context[:db_name]
+ create_doc(db_name, @ddoc)
+
+ resp = Couch.get("/#{db_name}/_design/update/_update/")
+ assert resp.status_code == 405
+ assert resp.body["error"] == "method_not_allowed"
+ assert resp.body["reason"] == "Only POST,PUT allowed"
+ end
+
+ @tag :with_db
test "update error invalid path", context do
db_name = context[:db_name]
create_doc(db_name, @ddoc)
@@ -135,7 +146,7 @@ defmodule UpdateDocumentsTest do
# Fix for COUCHDB-379
assert String.starts_with?(resp.headers["Server"], "CouchDB")
- resp = Couch.put("/#{db_name}/_design/update/_update/hello")
+ resp = Couch.post("/#{db_name}/_design/update/_update/hello")
assert resp.status_code == 200
assert resp.body == "<p>Empty World</p>"
end
@@ -246,7 +257,7 @@ defmodule UpdateDocumentsTest do
test "Server provides UUID when POSTing without an ID in the URL", context do
db_name = context[:db_name]
create_doc(db_name, @ddoc)
- resp = Couch.put("/#{db_name}/_design/update/_update/get-uuid/")
+ resp = Couch.post("/#{db_name}/_design/update/_update/get-uuid/")
assert resp.status_code == 200
assert String.length(resp.body) == 32
end
@@ -286,10 +297,10 @@ defmodule UpdateDocumentsTest do
assert resp.status_code == 200
assert resp.body["counter"] == 3
- resp = Couch.put("/#{db_name}/_design/update/_update/resp-code/")
+ resp = Couch.post("/#{db_name}/_design/update/_update/resp-code/")
assert resp.status_code == 302
- resp = Couch.put("/#{db_name}/_design/update/_update/resp-code-and-json/")
+ resp = Couch.post("/#{db_name}/_design/update/_update/resp-code-and-json/")
assert resp.status_code == 302
assert resp.body["ok"] == true
end