garrensmith commented on a change in pull request #1487: Port conflicts.js
URL: https://github.com/apache/couchdb/pull/1487#discussion_r208227766
 
 

 ##########
 File path: test/elixir/test/conflicts_test.exs
 ##########
 @@ -0,0 +1,109 @@
+defmodule RevisionTest do
+  use CouchTestCase
+
+  @moduletag :conflicts
+
+  @moduledoc """
+  Test CouchDB conflicts
+  This is a port of conflicts.js
+  (but is arguably more focused on revisions than conflicts)
+  """
+
+  setup context do
+    # Generate a doc with _rev field for each test
+    doc = %{_id: "doc-1", a: 1, b: 1}
+    doc = rev(doc, put(context[:db_name], doc))
+    %{doc: doc}
+  end
+
+  @tag :with_db
+  test "multiple updates with same _rev raise conflict errors", context do
+    db = context[:db_name]
+    doc = context[:doc]
+    doc2 = %{doc | a: 2, b: 2} # doc and doc2 have same _rev
+    _doc = rev(doc, put(db, doc)) # doc updated with new _rev
+    assert_conflict Couch.put("/#{db}/#{doc2._id}", [body: doc2])
+
+    resp = Couch.get("/#{db}/_changes")
+    assert length(resp.body["results"]) == 1
+
+    doc2 = Map.delete(doc2, :_rev)
+    assert_conflict(Couch.put("/#{db}/#{doc2._id}", [body: doc2]))
+  end
+
+  @tag :with_db
+  test "mismatched rev in body and query string returns error", context do
+    db = context[:db_name]
+    doc = context[:doc]
+    resp = Couch.put("/#{db}/#{doc._id}?rev=1-foobar", [body: doc])
+    expected_reason = "Document rev from request body and query string " <>
+      "have different values"
+    assert_bad_request(resp, expected_reason)
+  end
+
+  @tag :with_db
+  test "mismatched rev in body and etag returns error", context do
+    opts = [body: context[:doc], headers: [{:"If-Match", "1-foobar"}]]
+    resp = Couch.put("/#{context[:db_name]}/foobar", opts)
+    expected_reason = "Document rev and etag have different values"
+    assert_bad_request(resp, expected_reason)
+    # IO.inspect resp
 
 Review comment:
   Can you remove this commented out code.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to