You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2019/10/28 13:34:12 UTC

[couchdb] branch add-view-swap-test created (now 407fca6)

This is an automated email from the ASF dual-hosted git repository.

garren pushed a change to branch add-view-swap-test
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 407fca6  add test to prove we can view swap

This branch includes the following new commits:

     new 407fca6  add test to prove we can view swap

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: add test to prove we can view swap

Posted by ga...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

garren pushed a commit to branch add-view-swap-test
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 407fca6819b73707c2c5395ef30de63b7996bf08
Author: Garren Smith <ga...@gmail.com>
AuthorDate: Mon Oct 28 15:33:53 2019 +0200

    add test to prove we can view swap
---
 test/elixir/test/map_test.exs | 67 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/test/elixir/test/map_test.exs b/test/elixir/test/map_test.exs
index 04361ba..abc4556 100644
--- a/test/elixir/test/map_test.exs
+++ b/test/elixir/test/map_test.exs
@@ -436,6 +436,73 @@ defmodule ViewMapTest do
     assert Enum.at(rows, 9)["value"] == "multiple values!"
   end
 
+  test "can do design doc swap", context do
+    db_name = context[:db_name]
+
+    docs = [
+      %{_id: "doc1", foo: "foo", bar: "bar"},
+      %{
+        _id: "_design/view1",
+        views: %{
+          view: %{
+            map: """
+                function (doc) {
+                  if (!doc.foo) {
+                    return;
+                  }
+                  emit(doc.foo);
+                }
+            """
+          }
+        }
+      },
+      %{
+        _id: "_design/view2",
+        views: %{
+          view: %{
+            map: """
+                function (doc) {
+                  if (!doc.bar) {
+                    return;
+                  }
+                  emit(doc.bar);
+                }
+            """
+          }
+        }
+      }
+    ]
+
+    resp = Couch.post("/#{db_name}/_bulk_docs", body: %{:docs => docs})
+    assert resp.status_code == 201
+
+    url1 = "/#{db_name}/_design/view1/_view/view"
+    url2 = "/#{db_name}/_design/view2/_view/view"
+
+    resp = Couch.get(url1)
+    assert resp.status_code == 200
+    keys = get_keys(resp)
+    assert keys == ["foo"]
+
+    resp = Couch.get(url2)
+    assert resp.status_code == 200
+    keys = get_keys(resp)
+    assert keys == ["bar"]
+
+    view1 = Couch.get("/#{db_name}/_design/view1")
+    view2 = Couch.get("/#{db_name}/_design/view2")
+
+    new_view1 = Map.replace!(view1.body, "views", view2.body["views"])
+
+    resp = Couch.put("/#{db_name}/_design/view1", body: new_view1)
+    assert resp.status_code == 201
+
+    resp = Couch.get(url1, query: %{update: false})
+    assert resp.status_code == 200
+    keys = get_keys(resp)
+    assert keys == ["bar"]
+  end
+
   def update_doc_value(db_name, id, value) do
     resp = Couch.get("/#{db_name}/#{id}")
     doc = convert(resp.body)