summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2019-10-28 15:33:53 +0200
committergarren smith <garren.smith@gmail.com>2019-10-28 16:05:17 +0200
commit987efb3c09974fea700e5d31a2a50d097200b328 (patch)
tree1f28999a9e9d5a820ea9b15ab99669e450fe8319
parent3ded0e5a0b503289937bb9db7a40fd18f0810d3d (diff)
downloadcouchdb-987efb3c09974fea700e5d31a2a50d097200b328.tar.gz
add test to prove we can view swap
-rw-r--r--test/elixir/test/map_test.exs67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/elixir/test/map_test.exs b/test/elixir/test/map_test.exs
index 04361ba87..fa1758767 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 in [201, 202]
+
+ 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)