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

jiahuili430 pushed a commit to branch fix-elixir-tests
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 64dd7949e0f3e1c8c7970b6b0483c1f80d62f085
Author: Jiahui Li <[email protected]>
AuthorDate: Thu Dec 11 11:45:49 2025 -0600

    Update Elixir tests
    
    - Unit tests need to end with `_test.exs` to run them
      - large_docs_test.exs
      - reshard_changes_feed_test.exs
      - disk_monitor_test.exs
    
    -       The `Enum.each()` method cannot run tests because it iterates 
through
      the data at runtime, while the test macro is defined at compile time.
      Therefore, replace it with a for loop.
      - rewrite_js_test.exs
      - rewrite_test.exs
    
    - Update outdated tests.
      - cluster_with_quorum_test.exs
      - cluster_without_quorum_test.exs
      - cookie_auth_test.exs
---
 test/elixir/test/cluster_with_quorum_test.exs      |  20 +-
 test/elixir/test/cluster_without_quorum_test.exs   |  47 +-
 test/elixir/test/cookie_auth_test.exs              |  41 +-
 .../{disk_monitor.exs => disk_monitor_test.exs}    |   1 -
 .../{large_docs_text.exs => large_docs_test.exs}   |   0
 ...nges_feed.exs => reshard_changes_feed_test.exs} |   0
 test/elixir/test/rewrite_js_test.exs               | 361 ++++----
 test/elixir/test/rewrite_test.exs                  | 937 +++++++++++----------
 8 files changed, 688 insertions(+), 719 deletions(-)

diff --git a/test/elixir/test/cluster_with_quorum_test.exs 
b/test/elixir/test/cluster_with_quorum_test.exs
index fc3b28a0b..718e3f41b 100644
--- a/test/elixir/test/cluster_with_quorum_test.exs
+++ b/test/elixir/test/cluster_with_quorum_test.exs
@@ -7,14 +7,14 @@ defmodule WithQuorumTest do
   Test CouchDB API in a cluster without quorum.
   """
   @tag :with_db_name
-  test "Creating/Deleting DB should return 201-Created/202-Acepted", context do
+  test "Creating/Deleting DB should return 201-Created/200-OK", context do
     db_name = context[:db_name]
     resp = Couch.put("/#{db_name}")
     msg = "Should return 201-Created"
     assert resp.status_code in [201, 202], msg
     resp = Couch.delete("/#{db_name}")
-    msg = "Should return 202-Acepted"
-    assert resp.status_code == 202, msg
+    msg = "Should return 200-OK"
+    assert resp.status_code == 200, msg
   end
 
   @tag :with_db_name
@@ -45,7 +45,7 @@ defmodule WithQuorumTest do
   end
 
   @tag :with_db_name
-  test "Creating-Updating/Deleting doc with overriden quorum should return 
202-Acepted/200-OK",
+  test "Creating-Updating/Deleting doc with overridden quorum should return 
202-Accepted/200-OK",
        context do
     db_name = context[:db_name]
     Couch.put("/#{db_name}")
@@ -57,7 +57,7 @@ defmodule WithQuorumTest do
         body: %{:_id => "0", :a => 1}
       )
 
-    msg = "Should return 202-Acepted"
+    msg = "Should return 202-Accepted"
     assert resp.status_code == 202, msg
 
     resp = Couch.get("/#{context[:db_name]}/0")
@@ -70,7 +70,7 @@ defmodule WithQuorumTest do
         body: %{:_id => "0", :_rev => rev, :a => 2}
       )
 
-    msg = "Should return 202-Acepted"
+    msg = "Should return 202-Accepted"
     assert resp.status_code == 202, msg
 
     resp = Couch.get("/#{context[:db_name]}/0")
@@ -114,12 +114,12 @@ defmodule WithQuorumTest do
   end
 
   @tag :with_db_name
-  test "Bulk docs overriden quorum should return 202-Acepted", context do
+  test "Bulk docs overridden quorum should return 202-Accepted", context do
     db_name = context[:db_name]
     Couch.put("/#{db_name}")
     docs = create_docs(@doc_range)
     resp = Couch.post("/#{db_name}/_bulk_docs", query: %{:w => 3}, body: 
%{docs: docs})
-    msg = "Should return 202-Acepted"
+    msg = "Should return 202-Accepted"
     assert resp.status_code == 202, msg
 
     Couch.delete("/#{db_name}")
@@ -152,7 +152,7 @@ defmodule WithQuorumTest do
   end
 
   @tag :with_db_name
-  test "Attachments overriden quorum should return 202-Acepted", context do
+  test "Attachments overridden quorum should return 202-Accepted", context do
     db_name = context[:db_name]
     Couch.put("/#{db_name}")
     resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0"})
@@ -166,7 +166,7 @@ defmodule WithQuorumTest do
         headers: ["Content-Type": "text/plain;charset=utf-8"]
       )
 
-    msg = "Should return 202-Acepted"
+    msg = "Should return 202-Accepted"
     assert resp.status_code == 202, msg
 
     rev = resp.body["rev"]
diff --git a/test/elixir/test/cluster_without_quorum_test.exs 
b/test/elixir/test/cluster_without_quorum_test.exs
index e0095c351..16341c6ec 100644
--- a/test/elixir/test/cluster_without_quorum_test.exs
+++ b/test/elixir/test/cluster_without_quorum_test.exs
@@ -7,23 +7,24 @@ defmodule WithoutQuorumTest do
   Test CouchDB API in a cluster without quorum.
   """
   @tag :with_db_name
-  test "Creating/Deleting DB should return 202-Acepted", context do
+  test "Creating/Deleting DB should return 201-Created/200-OK", context do
     db_name = context[:db_name]
     resp = Couch.put("/#{db_name}")
-    msg = "Should return 202-Acepted"
-    assert resp.status_code == 202, msg
+    msg = "Should return 201-Created"
+    assert resp.status_code == 201, msg
     resp = Couch.delete("/#{db_name}")
-    assert resp.status_code == 202, msg
+    msg = "Should return 200-OK"
+    assert resp.status_code == 200, msg
   end
 
   @tag :with_db_name
-  test "Creating/Updating/Deleting doc should return 202-Acepted", context do
+  test "Creating/Updating/Deleting doc should return 201-Created/200-OK", 
context do
     db_name = context[:db_name]
     Couch.put("/#{db_name}")
 
     resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0", :a => 1})
-    msg = "Should return 202-Acepted"
-    assert resp.status_code == 202, msg
+    msg = "Should return 201-Created"
+    assert resp.status_code == 201, msg
 
     resp = Couch.get("/#{context[:db_name]}/0")
     rev = resp.body["_rev"]
@@ -31,20 +32,20 @@ defmodule WithoutQuorumTest do
     resp =
       Couch.put("/#{context[:db_name]}/0", body: %{:_id => "0", :_rev => rev, 
:a => 2})
 
-    msg = "Should return 202-Acepted"
-    assert resp.status_code == 202, msg
+    msg = "Should return 201-Created"
+    assert resp.status_code == 201, msg
 
     resp = Couch.get("/#{context[:db_name]}/0")
     rev = resp.body["_rev"]
     resp = Couch.delete("/#{context[:db_name]}/0", query: %{:rev => rev})
-    msg = "Should return 202-Acepted"
-    assert resp.status_code == 202, msg
+    msg = "Should return 200-OK"
+    assert resp.status_code == 200, msg
 
     Couch.delete("/#{db_name}")
   end
 
   @tag :with_db_name
-  test "Creating-Updating/Deleting doc with overriden quorum should return 
201-Created/200-OK",
+  test "Creating-Updating/Deleting doc with overridden quorum should return 
201-Created/200-OK",
        context do
     db_name = context[:db_name]
     Couch.put("/#{db_name}")
@@ -82,7 +83,7 @@ defmodule WithoutQuorumTest do
   end
 
   @tag :with_db_name
-  test "Copy doc should return 202-Acepted", context do
+  test "Copy doc should return 201-Created", context do
     db_name = context[:db_name]
     Couch.put("/#{db_name}")
 
@@ -93,27 +94,27 @@ defmodule WithoutQuorumTest do
 
     headers = [Destination: "1"]
     resp = Couch.request(:copy, "/#{context[:db_name]}/0", headers: headers)
-    msg = "Should return 202-Acepted"
-    assert resp.status_code == 202, msg
+    msg = "Should return 201-Created"
+    assert resp.status_code == 201, msg
     Couch.delete("/#{db_name}")
   end
 
   @doc_range 1..5
 
   @tag :with_db_name
-  test "Bulk docs should return 202-Acepted", context do
+  test "Bulk docs should return 201-Created", context do
     db_name = context[:db_name]
     Couch.put("/#{db_name}")
     docs = create_docs(@doc_range)
     resp = Couch.post("/#{db_name}/_bulk_docs", body: %{docs: docs})
-    msg = "Should return 202-Acepted"
-    assert resp.status_code == 202, msg
+    msg = "Should return 201-Created"
+    assert resp.status_code == 201, msg
 
     Couch.delete("/#{db_name}")
   end
 
   @tag :with_db_name
-  test "Bulk docs overriden quorum should return 201-Created", context do
+  test "Bulk docs overridden quorum should return 201-Created", context do
     db_name = context[:db_name]
     Couch.put("/#{db_name}")
     docs = create_docs(@doc_range)
@@ -125,7 +126,7 @@ defmodule WithoutQuorumTest do
   end
 
   @tag :with_db_name
-  test "Attachments should return 202-Acepted", context do
+  test "Attachments should return 201-Created", context do
     db_name = context[:db_name]
     Couch.put("/#{db_name}")
     resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0"})
@@ -139,8 +140,8 @@ defmodule WithoutQuorumTest do
         headers: ["Content-Type": "text/plain;charset=utf-8"]
       )
 
-    msg = "Should return 202-Acepted"
-    assert resp.status_code == 202, msg
+    msg = "Should return 201-Created"
+    assert resp.status_code == 201, msg
 
     rev = resp.body["rev"]
     resp = Couch.delete("/#{context[:db_name]}/0/foo.txt", query: %{:rev => 
rev})
@@ -151,7 +152,7 @@ defmodule WithoutQuorumTest do
   end
 
   @tag :with_db_name
-  test "Attachments overriden quorum should return 201-Created", context do
+  test "Attachments overridden quorum should return 201-Created", context do
     db_name = context[:db_name]
     Couch.put("/#{db_name}")
     resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0"})
diff --git a/test/elixir/test/cookie_auth_test.exs 
b/test/elixir/test/cookie_auth_test.exs
index cf9b36c7f..7cbac699f 100644
--- a/test/elixir/test/cookie_auth_test.exs
+++ b/test/elixir/test/cookie_auth_test.exs
@@ -374,45 +374,14 @@ defmodule CookieAuthTest do
     login("jan", "apple")
   end
 
-  test "basic+cookie auth interaction" do
+  test "header doesn't contain set-cookie" do
     # performing a successful basic authentication will create a session cookie
     resp = Couch.get(
-      "/_all_dbs",
-      no_auth: true,
-      headers: [authorization: "Basic #{:base64.encode("jan:apple")}"])
-    assert resp.status_code == 200
-
-    # extract cookie value
-    cookie = resp.headers[:"set-cookie"]
-    [token | _] = String.split(cookie, ";")
-
-    # Cookie is usable on its own
-    resp = Couch.get(
-      "/_session",
-      no_auth: true,
-      headers: [cookie: token])
-    assert resp.status_code == 200
-    assert resp.body["userCtx"]["name"]  == "jan"
-    assert resp.body["info"]["authenticated"] == "cookie"
+        "/_all_dbs",
+        no_auth: true,
+        headers: [authorization: "Basic #{:base64.encode("jan:apple")}"])
 
-    # Cookie is usable with basic auth if usernames match
-    resp = Couch.get(
-      "/_session",
-      no_auth: true,
-      headers: [
-        authorization: "Basic #{:base64.encode("jan:apple")}",
-        cookie: token])
     assert resp.status_code == 200
-    assert resp.body["userCtx"]["name"] == "jan"
-    assert resp.body["info"]["authenticated"] == "cookie"
-
-    # Cookie is not usable with basic auth if usernames don't match
-    resp = Couch.get(
-      "/_session",
-      no_auth: true,
-      headers: [
-        authorization: "Basic #{:base64.encode("notjan:banana")}",
-        cookie: token])
-    assert resp.status_code == 401
+    assert resp.headers["set-cookie"] == nil
   end
 end
diff --git a/test/elixir/test/disk_monitor.exs 
b/test/elixir/test/disk_monitor_test.exs
similarity index 99%
rename from test/elixir/test/disk_monitor.exs
rename to test/elixir/test/disk_monitor_test.exs
index 94a3edf99..1e93e0065 100644
--- a/test/elixir/test/disk_monitor.exs
+++ b/test/elixir/test/disk_monitor_test.exs
@@ -51,5 +51,4 @@ defmodule DiskMonitorTest do
     resp = Couch.post("/#{db_name}", body: %{:_id => "foo"})
     assert resp.status_code == 507
   end
-
 end
diff --git a/test/elixir/test/large_docs_text.exs 
b/test/elixir/test/large_docs_test.exs
similarity index 100%
rename from test/elixir/test/large_docs_text.exs
rename to test/elixir/test/large_docs_test.exs
diff --git a/test/elixir/test/reshard_changes_feed.exs 
b/test/elixir/test/reshard_changes_feed_test.exs
similarity index 100%
rename from test/elixir/test/reshard_changes_feed.exs
rename to test/elixir/test/reshard_changes_feed_test.exs
diff --git a/test/elixir/test/rewrite_js_test.exs 
b/test/elixir/test/rewrite_js_test.exs
index a3adb3e7d..d793e616a 100644
--- a/test/elixir/test/rewrite_js_test.exs
+++ b/test/elixir/test/rewrite_js_test.exs
@@ -209,203 +209,200 @@ defmodule RewriteJSTest do
     }
   }
 
-  Enum.each(
-    ["test_rewrite_suite_db", "test_rewrite_suite_db%2Fwith_slashes"],
-    fn db_name ->
-      @tag with_random_db: db_name
-      test "Test basic js rewrites on #{db_name}", context do
-        db_name = context[:db_name]
-
-        create_doc(db_name, @ddoc)
-
-        docs1 = make_docs(0..9)
-        bulk_save(db_name, docs1)
-
-        docs2 = [
-          %{"a" => 1, "b" => 1, "string" => "doc 1", "type" => "complex"},
-          %{"a" => 1, "b" => 2, "string" => "doc 2", "type" => "complex"},
-          %{"a" => "test", "b" => %{}, "string" => "doc 3", "type" => 
"complex"},
-          %{
-            "a" => "test",
-            "b" => ["test", "essai"],
-            "string" => "doc 4",
-            "type" => "complex"
-          },
-          %{"a" => %{"c" => 1}, "b" => "", "string" => "doc 5", "type" => 
"complex"}
-        ]
-
-        bulk_save(db_name, docs2)
-
-        # Test simple rewriting
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
-        assert resp.body == "This is a base64 encoded text"
-        assert resp.headers["Content-Type"] == "text/plain"
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo2")
-        assert resp.body == "This is a base64 encoded text"
-        assert resp.headers["Content-Type"] == "text/plain"
-
-        # Test POST, hello update world
-        resp =
-          Couch.post("/#{db_name}", body: %{"word" => "plankton", "name" => 
"Rusty"}).body
-
-        assert resp["ok"]
-        doc_id = resp["id"]
-        assert doc_id
-
-        resp = Couch.put("/#{db_name}/_design/test/_rewrite/hello/#{doc_id}")
-        assert resp.status_code in [201, 202]
-        assert resp.body == "hello doc"
-        assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
-
-        assert Couch.get("/#{db_name}/#{doc_id}").body["world"] == "hello"
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome?name=user")
-        assert resp.body == "Welcome user"
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome/user")
-        assert resp.body == "Welcome user"
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome2")
-        assert resp.body == "Welcome user"
-
-        resp = Couch.put("/#{db_name}/_design/test/_rewrite/welcome3/test")
-        assert resp.status_code in [201, 202]
-        assert resp.body == "New World"
-        assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome3/test")
-        assert resp.body == "Welcome test"
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome4/user")
-        assert resp.body == "Welcome user"
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome5/welcome3")
-        assert resp.body == "Welcome welcome3"
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/basicView")
-        assert resp.status_code == 200
-        assert resp.body["total_rows"] == 9
-
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView")
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/FirstKey: [1, 2]/)
-
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView2")
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/Value: doc 3/)
-
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView3")
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/Value: doc 4/)
-
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView4")
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/Value: doc 5/)
-
-        # COUCHDB-1612 - send body rewriting get to post
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/sendBody1")
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/Value: doc 5 LineNo: 1/)
-
-        resp = 
Couch.get("/#{db_name}/_design/test/_rewrite/db/_design/test?meta=true")
-        assert resp.status_code == 200
-        assert resp.body["_id"] == "_design/test"
-        assert Map.has_key?(resp.body, "_revs_info")
-      end
-
-      @tag with_random_db: db_name
-      test "early response on #{db_name}", context do
-        db_name = context[:db_name]
-
-        ddoc = %{
-          _id: "_design/response",
-          rewrites: """
-           function(req){
-            status = parseInt(req.query.status);
-            return {code: status,
-                    body: JSON.stringify({"status": status}),
-                    headers: {'x-foo': 'bar', 'Content-Type': 
'application/json'}};
-          }
-          """
+  for db_name <- ["test_rewrite_suite_db", 
"test_rewrite_suite_db%2Fwith_slashes"] do
+    @tag with_random_db: db_name
+    test "basic js rewrites on #{db_name}", context do
+      db_name = context[:db_name]
+
+      create_doc(db_name, @ddoc)
+
+      docs1 = make_docs(0..9)
+      bulk_save(db_name, docs1)
+
+      docs2 = [
+        %{"a" => 1, "b" => 1, "string" => "doc 1", "type" => "complex"},
+        %{"a" => 1, "b" => 2, "string" => "doc 2", "type" => "complex"},
+        %{"a" => "test", "b" => %{}, "string" => "doc 3", "type" => "complex"},
+        %{
+          "a" => "test",
+          "b" => ["test", "essai"],
+          "string" => "doc 4",
+          "type" => "complex"
+        },
+        %{"a" => %{"c" => 1}, "b" => "", "string" => "doc 5", "type" => 
"complex"}
+      ]
+
+      bulk_save(db_name, docs2)
+
+      # Test simple rewriting
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
+      assert resp.body == "This is a base64 encoded text"
+      assert resp.headers["Content-Type"] == "text/plain"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo2")
+      assert resp.body == "This is a base64 encoded text"
+      assert resp.headers["Content-Type"] == "text/plain"
+
+      # Test POST, hello update world
+      resp =
+        Couch.post("/#{db_name}", body: %{"word" => "plankton", "name" => 
"Rusty"}).body
+
+      assert resp["ok"]
+      doc_id = resp["id"]
+      assert doc_id
+
+      resp = Couch.put("/#{db_name}/_design/test/_rewrite/hello/#{doc_id}")
+      assert resp.status_code in [201, 202]
+      assert resp.body == "hello doc"
+      assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+
+      assert Couch.get("/#{db_name}/#{doc_id}").body["world"] == "hello"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome?name=user")
+      assert resp.body == "Welcome user"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome/user")
+      assert resp.body == "Welcome user"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome2")
+      assert resp.body == "Welcome user"
+
+      resp = Couch.put("/#{db_name}/_design/test/_rewrite/welcome3/test")
+      assert resp.status_code in [201, 202]
+      assert resp.body == "New World"
+      assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome3/test")
+      assert resp.body == "Welcome test"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome4/user")
+      assert resp.body == "Welcome user"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome5/welcome3")
+      assert resp.body == "Welcome welcome3"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/basicView")
+      assert resp.status_code == 200
+      assert resp.body["total_rows"] == 9
+
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView")
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/FirstKey: [1, 2]/)
+
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView2")
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/Value: doc 3/)
+
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView3")
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/Value: doc 4/)
+
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView4")
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/Value: doc 5/)
+
+      # COUCHDB-1612 - send body rewriting get to post
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/sendBody1")
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/Value: doc 5 LineNo: 1/)
+
+      resp = 
Couch.get("/#{db_name}/_design/test/_rewrite/db/_design/test?meta=true")
+      assert resp.status_code == 200
+      assert resp.body["_id"] == "_design/test"
+      assert Map.has_key?(resp.body, "_revs_info")
+    end
+
+    @tag with_random_db: db_name
+    test "early response on #{db_name}", context do
+      db_name = context[:db_name]
+
+      ddoc = %{
+        _id: "_design/response",
+        rewrites: """
+         function(req){
+          status = parseInt(req.query.status);
+          return {code: status,
+                  body: JSON.stringify({"status": status}),
+                  headers: {'x-foo': 'bar', 'Content-Type': 
'application/json'}};
         }
+        """
+      }
 
-        create_doc(db_name, ddoc)
+      create_doc(db_name, ddoc)
 
-        resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=200")
-        assert resp.status_code == 200
-        assert resp.headers["x-foo"] == "bar"
-        assert resp.body["status"] == 200
+      resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=200")
+      assert resp.status_code == 200
+      assert resp.headers["x-foo"] == "bar"
+      assert resp.body["status"] == 200
 
-        resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=451")
-        assert resp.status_code == 451
-        assert resp.headers["Content-Type"] == "application/json"
+      resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=451")
+      assert resp.status_code == 451
+      assert resp.headers["Content-Type"] == "application/json"
 
-        resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=500")
-        assert resp.status_code == 500
-      end
+      resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=500")
+      assert resp.status_code == 500
+    end
 
-      @tag with_random_db: db_name
-      test "path relative to server on #{db_name}", context do
-        db_name = context[:db_name]
+    @tag with_random_db: db_name
+    test "path relative to server on #{db_name}", context do
+      db_name = context[:db_name]
 
-        ddoc = %{
-          _id: "_design/relative",
-          rewrites: """
-           function(req){
-            return '../../../_uuids'
-          }
-          """
+      ddoc = %{
+        _id: "_design/relative",
+        rewrites: """
+         function(req){
+          return '../../../_uuids'
         }
+        """
+      }
 
-        create_doc(db_name, ddoc)
-        resp = Couch.get("/#{db_name}/_design/relative/_rewrite/uuids")
-        assert resp.status_code == 200
-        assert length(resp.body["uuids"]) == 1
-      end
-
-      @tag with_random_db: db_name
-      test "loop on #{db_name}", context do
-        db_name = context[:db_name]
-
-        ddoc_loop = %{
-          _id: "_design/loop",
-          rewrites: """
-          function(req) {
-            return '_rewrite/loop';
-          }
-          """
+      create_doc(db_name, ddoc)
+      resp = Couch.get("/#{db_name}/_design/relative/_rewrite/uuids")
+      assert resp.status_code == 200
+      assert length(resp.body["uuids"]) == 1
+    end
+
+    @tag with_random_db: db_name
+    test "loop on #{db_name}", context do
+      db_name = context[:db_name]
+
+      ddoc_loop = %{
+        _id: "_design/loop",
+        rewrites: """
+        function(req) {
+          return '_rewrite/loop';
         }
+        """
+      }
 
-        create_doc(db_name, ddoc_loop)
-        resp = Couch.get("/#{db_name}/_design/loop/_rewrite/loop")
-        assert resp.status_code == 400
-      end
+      create_doc(db_name, ddoc_loop)
+      resp = Couch.get("/#{db_name}/_design/loop/_rewrite/loop")
+      assert resp.status_code == 400
+    end
 
-      @tag with_random_db: db_name
-      test "requests with body preserve the query string rewrite on 
#{db_name}",
-           context do
-        db_name = context[:db_name]
+    @tag with_random_db: db_name
+    test "requests with body preserve the query string rewrite on #{db_name}",
+         context do
+      db_name = context[:db_name]
 
-        ddoc_qs = %{
-          _id: "_design/qs",
-          rewrites:
-            "function (r) { return {path: '../../_changes', query: {'filter': 
'_doc_ids'}};};"
-        }
+      ddoc_qs = %{
+        _id: "_design/qs",
+        rewrites:
+          "function (r) { return {path: '../../_changes', query: {'filter': 
'_doc_ids'}};};"
+      }
 
-        create_doc(db_name, ddoc_qs)
-        create_doc(db_name, %{_id: "qs1"})
-        create_doc(db_name, %{_id: "qs2"})
+      create_doc(db_name, ddoc_qs)
+      create_doc(db_name, %{_id: "qs1"})
+      create_doc(db_name, %{_id: "qs2"})
 
-        resp =
-          Couch.post("/#{db_name}/_design/qs/_rewrite",
-            body: %{doc_ids: ["qs2"]}
-          )
+      resp =
+        Couch.post("/#{db_name}/_design/qs/_rewrite",
+          body: %{doc_ids: ["qs2"]}
+        )
 
-        assert resp.status_code == 200
-        assert length(resp.body["results"]) == 1
-        assert Enum.at(resp.body["results"], 0)["id"] == "qs2"
-      end
+      assert resp.status_code == 200
+      assert length(resp.body["results"]) == 1
+      assert Enum.at(resp.body["results"], 0)["id"] == "qs2"
     end
-  )
+  end
 end
diff --git a/test/elixir/test/rewrite_test.exs 
b/test/elixir/test/rewrite_test.exs
index 34fe3b7f5..4a13803c6 100644
--- a/test/elixir/test/rewrite_test.exs
+++ b/test/elixir/test/rewrite_test.exs
@@ -8,519 +8,522 @@ defmodule RewriteTest do
   This is a port of the rewrite.js suite
   """
 
-  Enum.each(
-    ["test_rewrite_suite_db", "test_rewrite_suite_db%2Fwith_slashes"],
-    fn db_name ->
-      @tag with_random_db: db_name
-      @tag config: [
-             {"httpd", "authentication_handlers",
-              "{couch_httpd_auth, special_test_authentication_handler}"},
-             {"chttpd", "WWW-Authenticate", "X-Couch-Test-Auth"}
-           ]
-      test "Test basic rewrites on #{db_name}", context do
-        db_name = context[:db_name]
-
-        ddoc = ~S"""
-        {
-          "_id": "_design/test",
-          "language": "javascript",
-          "_attachments": {
-            "foo.txt": {
-              "content_type":"text/plain",
-              "data": "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
+  for db_name <- ["test_rewrite_suite_db", 
"test_rewrite_suite_db%2Fwith_slashes"] do
+    @tag with_random_db: db_name
+    @tag config: [
+           {"httpd", "authentication_handlers",
+            "{couch_httpd_auth, special_test_authentication_handler}"},
+           {"chttpd", "WWW-Authenticate", "X-Couch-Test-Auth"}
+         ]
+    test "basic rewrites on #{db_name}", context do
+      db_name = context[:db_name]
+
+      ddoc = ~S"""
+      {
+        "_id": "_design/test",
+        "language": "javascript",
+        "_attachments": {
+          "foo.txt": {
+            "content_type":"text/plain",
+            "data": "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
+          }
+        },
+        "rewrites": [
+          {
+            "from": "foo",
+            "to": "foo.txt"
+          },
+          {
+            "from": "foo2",
+            "to": "foo.txt",
+            "method": "GET"
+          },
+          {
+            "from": "hello/:id",
+            "to": "_update/hello/:id",
+            "method": "PUT"
+          },
+          {
+            "from": "/welcome",
+            "to": "_show/welcome"
+          },
+          {
+            "from": "/welcome/:name",
+            "to": "_show/welcome",
+            "query": {
+              "name": ":name"
             }
           },
-          "rewrites": [
-            {
-              "from": "foo",
-              "to": "foo.txt"
-            },
-            {
-              "from": "foo2",
-              "to": "foo.txt",
-              "method": "GET"
-            },
-            {
-              "from": "hello/:id",
-              "to": "_update/hello/:id",
-              "method": "PUT"
-            },
-            {
-              "from": "/welcome",
-              "to": "_show/welcome"
-            },
-            {
-              "from": "/welcome/:name",
-              "to": "_show/welcome",
-              "query": {
-                "name": ":name"
-              }
-            },
-            {
-              "from": "/welcome2",
-              "to": "_show/welcome",
-              "query": {
-                "name": "user"
-              }
-            },
-            {
-              "from": "/welcome3/:name",
-              "to": "_update/welcome2/:name",
-              "method": "PUT"
-            },
-            {
-              "from": "/welcome3/:name",
-              "to": "_show/welcome2/:name",
-              "method": "GET"
-            },
-            {
-              "from": "/welcome4/*",
-              "to" : "_show/welcome3",
-              "query": {
-                "name": "*"
-              }
-            },
-            {
-              "from": "/welcome5/*",
-              "to" : "_show/*",
-              "query": {
-                "name": "*"
-              }
-            },
-            {
-              "from": "basicView",
-              "to": "_view/basicView"
-            },
-            {
-              "from": "simpleForm/basicView",
-              "to": "_list/simpleForm/basicView"
-            },
-            {
-              "from": "simpleForm/basicViewFixed",
-              "to": "_list/simpleForm/basicView",
-              "query": {
-                "startkey": 3,
-                "endkey": 8
-              }
-            },
-            {
-              "from": "simpleForm/basicViewPath/:start/:end",
-              "to": "_list/simpleForm/basicView",
-              "query": {
-                "startkey": ":start",
-                "endkey": ":end"
-              },
-              "formats": {
-                "start": "int",
-                "end": "int"
-              }
-            },
-            {
-              "from": "simpleForm/complexView",
-              "to": "_list/simpleForm/complexView",
-              "query": {
-                "key": [1, 2]
-              }
-            },
-            {
-              "from": "simpleForm/complexView2",
-              "to": "_list/simpleForm/complexView",
-              "query": {
-                "key": ["test", {}]
-              }
-            },
-            {
-              "from": "simpleForm/complexView3",
-              "to": "_list/simpleForm/complexView",
-              "query": {
-                "key": ["test", ["test", "essai"]]
-              }
-            },
-            {
-              "from": "simpleForm/complexView4",
-              "to": "_list/simpleForm/complexView2",
-              "query": {
-                "key": {"c": 1}
-              }
+          {
+            "from": "/welcome2",
+            "to": "_show/welcome",
+            "query": {
+              "name": "user"
+            }
+          },
+          {
+            "from": "/welcome3/:name",
+            "to": "_update/welcome2/:name",
+            "method": "PUT"
+          },
+          {
+            "from": "/welcome3/:name",
+            "to": "_show/welcome2/:name",
+            "method": "GET"
+          },
+          {
+            "from": "/welcome4/*",
+            "to" : "_show/welcome3",
+            "query": {
+              "name": "*"
+            }
+          },
+          {
+            "from": "/welcome5/*",
+            "to" : "_show/*",
+            "query": {
+              "name": "*"
+            }
+          },
+          {
+            "from": "basicView",
+            "to": "_view/basicView"
+          },
+          {
+            "from": "simpleForm/basicView",
+            "to": "_list/simpleForm/basicView"
+          },
+          {
+            "from": "simpleForm/basicViewFixed",
+            "to": "_list/simpleForm/basicView",
+            "query": {
+              "startkey": 3,
+              "endkey": 8
+            }
+          },
+          {
+            "from": "simpleForm/basicViewPath/:start/:end",
+            "to": "_list/simpleForm/basicView",
+            "query": {
+              "startkey": ":start",
+              "endkey": ":end"
             },
-            {
-              "from": "simpleForm/complexView5/:a/:b",
-              "to": "_list/simpleForm/complexView3",
-              "query": {
-                "key": [":a", ":b"]
-              }
+            "formats": {
+              "start": "int",
+              "end": "int"
+            }
+          },
+          {
+            "from": "simpleForm/complexView",
+            "to": "_list/simpleForm/complexView",
+            "query": {
+              "key": [1, 2]
+            }
+          },
+          {
+            "from": "simpleForm/complexView2",
+            "to": "_list/simpleForm/complexView",
+            "query": {
+              "key": ["test", {}]
+            }
+          },
+          {
+            "from": "simpleForm/complexView3",
+            "to": "_list/simpleForm/complexView",
+            "query": {
+              "key": ["test", ["test", "essai"]]
+            }
+          },
+          {
+            "from": "simpleForm/complexView4",
+            "to": "_list/simpleForm/complexView2",
+            "query": {
+              "key": {"c": 1}
+            }
+          },
+          {
+            "from": "simpleForm/complexView5/:a/:b",
+            "to": "_list/simpleForm/complexView3",
+            "query": {
+              "key": [":a", ":b"]
+            }
+          },
+          {
+            "from": "simpleForm/complexView6",
+            "to": "_list/simpleForm/complexView3",
+            "query": {
+              "key": [":a", ":b"]
+            }
+          },
+          {
+            "from": "simpleForm/complexView7/:a/:b",
+            "to": "_view/complexView3",
+            "query": {
+              "key": [":a", ":b"],
+              "include_docs": ":doc"
             },
-            {
-              "from": "simpleForm/complexView6",
-              "to": "_list/simpleForm/complexView3",
-              "query": {
-                "key": [":a", ":b"]
+            "format": {
+              "doc": "bool"
+            }
+
+          },
+          {
+            "from": "/",
+            "to": "_view/basicView"
+          },
+          {
+            "from": "/db/*",
+            "to": "../../*"
+          }
+        ],
+        "lists": {
+          "simpleForm": "function(head, req) {
+            log(\"simpleForm\");
+            send(\"<ul>\");
+            var row, row_number = 0, prevKey, firstKey = null;
+            while (row = getRow()) {
+              row_number += 1;
+              if (!firstKey) firstKey = row.key;
+              prevKey = row.key;
+              send(\"\\n<li>Key: \"+row.key
+                   +\" Value: \"+row.value
+                   +\" LineNo: \"+row_number+\"</li>\");
+            }
+            return \"</ul><p>FirstKey: \"+ firstKey + \" LastKey: \"+ 
prevKey+\"</p>\";
+          }"
+        },
+        "shows": {
+          "welcome": "(function(doc,req) {
+            return \"Welcome \" + req.query[\"name\"];
+          })",
+          "welcome2": "(function(doc, req) {
+            return \"Welcome \" + doc.name;
+          })",
+          "welcome3": "(function(doc,req) {
+            return \"Welcome \" + req.query[\"name\"];
+          })"
+        },
+        "updates": {
+          "hello" : "(function(doc, req) {
+            if (!doc) {
+              if (req.id) {
+                return [{
+                  _id : req.id
+                }, \"New World\"]
               }
-            },
-            {
-              "from": "simpleForm/complexView7/:a/:b",
-              "to": "_view/complexView3",
-              "query": {
-                "key": [":a", ":b"],
-                "include_docs": ":doc"
-              },
-              "format": {
-                "doc": "bool"
+              return [null, \"Empty World\"];
+            }
+            doc.world = \"hello\";
+            doc.edited_by = req.userCtx;
+            return [doc, \"hello doc\"];
+          })",
+          "welcome2": "(function(doc, req) {
+            if (!doc) {
+              if (req.id) {
+                return [{
+                  _id: req.id,
+                  name: req.id
+                }, \"New World\"]
               }
-
-            },
-            {
-              "from": "/",
-              "to": "_view/basicView"
-            },
-            {
-              "from": "/db/*",
-              "to": "../../*"
+              return [null, \"Empty World\"];
             }
-          ],
-          "lists": {
-            "simpleForm": "function(head, req) {
-              log(\"simpleForm\");
-              send(\"<ul>\");
-              var row, row_number = 0, prevKey, firstKey = null;
-              while (row = getRow()) {
-                row_number += 1;
-                if (!firstKey) firstKey = row.key;
-                prevKey = row.key;
-                send(\"\\n<li>Key: \"+row.key
-                     +\" Value: \"+row.value
-                     +\" LineNo: \"+row_number+\"</li>\");
+            return [doc, \"hello doc\"];
+          })"
+        },
+        "views" : {
+          "basicView" : {
+            "map" : "(function(doc) {
+              if (doc.integer) {
+                emit(doc.integer, doc.string);
               }
-              return \"</ul><p>FirstKey: \"+ firstKey + \" LastKey: \"+ 
prevKey+\"</p>\";
-            }"
-          },
-          "shows": {
-            "welcome": "(function(doc,req) {
-              return \"Welcome \" + req.query[\"name\"];
-            })",
-            "welcome2": "(function(doc, req) {
-              return \"Welcome \" + doc.name;
-            })",
-            "welcome3": "(function(doc,req) {
-              return \"Welcome \" + req.query[\"name\"];
+
             })"
           },
-          "updates": {
-            "hello" : "(function(doc, req) {
-              if (!doc) {
-                if (req.id) {
-                  return [{
-                    _id : req.id
-                  }, \"New World\"]
-                }
-                return [null, \"Empty World\"];
+          "complexView": {
+            "map": "(function(doc) {
+              if (doc.type == \"complex\") {
+                emit([doc.a, doc.b], doc.string);
               }
-              doc.world = \"hello\";
-              doc.edited_by = req.userCtx;
-              return [doc, \"hello doc\"];
-            })",
-            "welcome2": "(function(doc, req) {
-              if (!doc) {
-                if (req.id) {
-                  return [{
-                    _id: req.id,
-                    name: req.id
-                  }, \"New World\"]
-                }
-                return [null, \"Empty World\"];
+            })"
+          },
+          "complexView2": {
+            "map": "(function(doc) {
+              if (doc.type == \"complex\") {
+                emit(doc.a, doc.string);
               }
-              return [doc, \"hello doc\"];
             })"
           },
-          "views" : {
-            "basicView" : {
-              "map" : "(function(doc) {
-                if (doc.integer) {
-                  emit(doc.integer, doc.string);
-                }
-
-              })"
-            },
-            "complexView": {
-              "map": "(function(doc) {
-                if (doc.type == \"complex\") {
-                  emit([doc.a, doc.b], doc.string);
-                }
-              })"
-            },
-            "complexView2": {
-              "map": "(function(doc) {
-                if (doc.type == \"complex\") {
-                  emit(doc.a, doc.string);
-                }
-              })"
-            },
-            "complexView3": {
-              "map": "(function(doc) {
-                if (doc.type == \"complex\") {
-                  emit(doc.b, doc.string);
-                }
-              })"
-            }
+          "complexView3": {
+            "map": "(function(doc) {
+              if (doc.type == \"complex\") {
+                emit(doc.b, doc.string);
+              }
+            })"
           }
         }
-        """
-
-        ddoc = String.replace(ddoc, ~r/[\r\n]+/, "")
-
-        docs1 = make_docs(0..9)
-
-        docs2 = [
-          %{"a" => 1, "b" => 1, "string" => "doc 1", "type" => "complex"},
-          %{"a" => 1, "b" => 2, "string" => "doc 2", "type" => "complex"},
-          %{"a" => "test", "b" => %{}, "string" => "doc 3", "type" => 
"complex"},
-          %{
-            "a" => "test",
-            "b" => ["test", "essai"],
-            "string" => "doc 4",
-            "type" => "complex"
-          },
-          %{"a" => %{"c" => 1}, "b" => "", "string" => "doc 5", "type" => 
"complex"}
-        ]
-
-        assert Couch.put("/#{db_name}/_design/test", body: ddoc).body["ok"]
-
-        assert Couch.post(
-                 "/#{db_name}/_bulk_docs",
-                 body: %{:docs => docs1},
-                 query: %{w: 3}
-               ).status_code in [201, 202]
-
-        assert Couch.post(
-                 "/#{db_name}/_bulk_docs",
-                 body: %{:docs => docs2},
-                 query: %{w: 3}
-               ).status_code in [201, 202]
-
-        # Test simple rewriting
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
-        assert resp.body == "This is a base64 encoded text"
-        assert resp.headers["Content-Type"] == "text/plain"
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo2")
-        assert resp.body == "This is a base64 encoded text"
-        assert resp.headers["Content-Type"] == "text/plain"
-
-        # Test POST, hello update world
-        resp =
-          Couch.post("/#{db_name}", body: %{"word" => "plankton", "name" => 
"Rusty"}).body
-
-        assert resp["ok"]
-        doc_id = resp["id"]
-        assert doc_id
-
-        resp = Couch.put("/#{db_name}/_design/test/_rewrite/hello/#{doc_id}")
-        assert resp.status_code in [201, 202]
-        assert resp.body == "hello doc"
-        assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+      }
+      """
+
+      ddoc = String.replace(ddoc, ~r/[\r\n]+/, "")
+
+      docs1 = make_docs(0..9)
+
+      docs2 = [
+        %{"a" => 1, "b" => 1, "string" => "doc 1", "type" => "complex"},
+        %{"a" => 1, "b" => 2, "string" => "doc 2", "type" => "complex"},
+        %{"a" => "test", "b" => %{}, "string" => "doc 3", "type" => "complex"},
+        %{
+          "a" => "test",
+          "b" => ["test", "essai"],
+          "string" => "doc 4",
+          "type" => "complex"
+        },
+        %{"a" => %{"c" => 1}, "b" => "", "string" => "doc 5", "type" => 
"complex"}
+      ]
+
+      assert Couch.put("/#{db_name}/_design/test", body: ddoc).body["ok"]
+
+      assert Couch.post(
+               "/#{db_name}/_bulk_docs",
+               body: %{:docs => docs1},
+               query: %{w: 3}
+             ).status_code in [201, 202]
+
+      assert Couch.post(
+               "/#{db_name}/_bulk_docs",
+               body: %{:docs => docs2},
+               query: %{w: 3}
+             ).status_code in [201, 202]
+
+      # Test simple rewriting
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
+      assert resp.body == "This is a base64 encoded text"
+      assert resp.headers["Content-Type"] == "text/plain"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo2")
+      assert resp.body == "This is a base64 encoded text"
+      assert resp.headers["Content-Type"] == "text/plain"
+
+      # Test POST, hello update world
+      resp =
+        Couch.post("/#{db_name}", body: %{"word" => "plankton", "name" => 
"Rusty"}).body
+
+      assert resp["ok"]
+      doc_id = resp["id"]
+      assert doc_id
+
+      resp = Couch.put("/#{db_name}/_design/test/_rewrite/hello/#{doc_id}")
+      assert resp.status_code in [201, 202]
+      assert resp.body == "hello doc"
+      assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+
+      assert Couch.get("/#{db_name}/#{doc_id}").body["world"] == "hello"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome?name=user")
+      assert resp.body == "Welcome user"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome/user")
+      assert resp.body == "Welcome user"
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome2")
+      assert resp.body == "Welcome user"
+
+      resp = Couch.put("/#{db_name}/_design/test/_rewrite/welcome3/test")
+      assert resp.status_code in [201, 202]
+      assert resp.body == "New World"
+      assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome3/test")
+      assert resp.body == "Welcome test"
 
-        assert Couch.get("/#{db_name}/#{doc_id}").body["world"] == "hello"
+      # TODO: port the two "bugged" tests from rewrite.js
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite/basicView")
+      assert resp.status_code == 200
+      assert resp.body["total_rows"] == 9
+
+      resp = Couch.get("/#{db_name}/_design/test/_rewrite")
+      assert resp.status_code == 200
+      assert resp.body["total_rows"] == 9
+
+      resp =
+        Rawresp.get(
+          
"/#{db_name}/_design/test/_rewrite/simpleForm/basicView?startkey=3&endkey=8"
+        )
+
+      assert resp.status_code == 200
+      assert not String.match?(resp.body, ~r/Key: 1/)
+      assert String.match?(resp.body, ~r/FirstKey: 3/)
+      assert String.match?(resp.body, ~r/LastKey: 8/)
+
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/basicViewFixed")
+      assert resp.status_code == 200
+      assert not String.match?(resp.body, ~r/Key: 1/)
+      assert String.match?(resp.body, ~r/FirstKey: 3/)
+      assert String.match?(resp.body, ~r/LastKey: 8/)
+
+      resp =
+        Rawresp.get(
+          
"/#{db_name}/_design/test/_rewrite/simpleForm/basicViewFixed?startkey=4"
+        )
+
+      assert resp.status_code == 200
+      assert not String.match?(resp.body, ~r/Key: 1/)
+      assert String.match?(resp.body, ~r/FirstKey: 3/)
+      assert String.match?(resp.body, ~r/LastKey: 8/)
+
+      resp =
+        
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/basicViewPath/3/8")
+
+      assert resp.status_code == 200
+      assert not String.match?(resp.body, ~r/Key: 1/)
+      assert String.match?(resp.body, ~r/FirstKey: 3/)
+      assert String.match?(resp.body, ~r/LastKey: 8/)
 
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome?name=user")
-        assert resp.body == "Welcome user"
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView")
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/FirstKey: [1, 2]/)
 
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome/user")
-        assert resp.body == "Welcome user"
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView2")
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/Value: doc 3/)
 
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome2")
-        assert resp.body == "Welcome user"
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView3")
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/Value: doc 4/)
 
-        resp = Couch.put("/#{db_name}/_design/test/_rewrite/welcome3/test")
-        assert resp.status_code in [201, 202]
-        assert resp.body == "New World"
-        assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView4")
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/Value: doc 5/)
 
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome3/test")
-        assert resp.body == "Welcome test"
+      resp =
+        Rawresp.get(
+          
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView5/test/essai"
+        )
 
-        # TODO: port the two "bugged" tests from rewrite.js
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite/basicView")
-        assert resp.status_code == 200
-        assert resp.body["total_rows"] == 9
-
-        resp = Couch.get("/#{db_name}/_design/test/_rewrite")
-        assert resp.status_code == 200
-        assert resp.body["total_rows"] == 9
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/Value: doc 4/)
 
-        resp =
-          Rawresp.get(
-            
"/#{db_name}/_design/test/_rewrite/simpleForm/basicView?startkey=3&endkey=8"
-          )
+      resp =
+        Rawresp.get(
+          
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView6?a=test&b=essai"
+        )
 
-        assert resp.status_code == 200
-        assert not String.match?(resp.body, ~r/Key: 1/)
-        assert String.match?(resp.body, ~r/FirstKey: 3/)
-        assert String.match?(resp.body, ~r/LastKey: 8/)
+      assert resp.status_code == 200
+      assert String.match?(resp.body, ~r/Value: doc 4/)
 
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/basicViewFixed")
-        assert resp.status_code == 200
-        assert not String.match?(resp.body, ~r/Key: 1/)
-        assert String.match?(resp.body, ~r/FirstKey: 3/)
-        assert String.match?(resp.body, ~r/LastKey: 8/)
+      resp =
+        Rawresp.get(
+          
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView7/test/essai?doc=true"
+        )
 
-        resp =
-          Rawresp.get(
-            
"/#{db_name}/_design/test/_rewrite/simpleForm/basicViewFixed?startkey=4"
-          )
+      assert resp.status_code == 200
 
-        assert resp.status_code == 200
-        assert not String.match?(resp.body, ~r/Key: 1/)
-        assert String.match?(resp.body, ~r/FirstKey: 3/)
-        assert String.match?(resp.body, ~r/LastKey: 8/)
+      result =
+        resp.body |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps, 
:use_nil])
 
-        resp =
-          
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/basicViewPath/3/8")
+      first_row = Enum.at(result["rows"], 0)
+      assert Map.has_key?(first_row, "doc")
 
-        assert resp.status_code == 200
-        assert not String.match?(resp.body, ~r/Key: 1/)
-        assert String.match?(resp.body, ~r/FirstKey: 3/)
-        assert String.match?(resp.body, ~r/LastKey: 8/)
+      # COUCHDB-2031 - path normalization versus qs params
+      resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/db/_design/test?meta=true")
+      assert resp.status_code == 200
 
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView")
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/FirstKey: [1, 2]/)
+      result =
+        resp.body |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps, 
:use_nil])
 
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView2")
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/Value: doc 3/)
+      assert result["_id"] == "_design/test"
+      assert Map.has_key?(result, "_revs_info")
 
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView3")
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/Value: doc 4/)
+      ddoc2 = %{
+        _id: "_design/test2",
+        rewrites: [
+          %{
+            from: "uuids",
+            to: "../../../_uuids"
+          }
+        ]
+      }
 
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView4")
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/Value: doc 5/)
+      create_doc(db_name, ddoc2)
+      resp = Couch.get("/#{db_name}/_design/test2/_rewrite/uuids")
+      assert resp.status_code == 500
+      assert resp.body["error"] == "insecure_rewrite_rule"
+    end
 
-        resp =
-          Rawresp.get(
-            
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView5/test/essai"
-          )
+    @tag with_random_db: db_name
+    @tag config: [
+           {"chttpd", "secure_rewrites", "false"}
+         ]
+    test "path relative to server on #{db_name}", context do
+      db_name = context[:db_name]
 
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/Value: doc 4/)
+      ddoc = %{
+        _id: "_design/test2",
+        rewrites: [
+          %{
+            from: "uuids",
+            to: "../../../_uuids"
+          }
+        ]
+      }
 
-        resp =
-          Rawresp.get(
-            
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView6?a=test&b=essai"
-          )
+      create_doc(db_name, ddoc)
 
-        assert resp.status_code == 200
-        assert String.match?(resp.body, ~r/Value: doc 4/)
+      resp = Couch.get("/#{db_name}/_design/test2/_rewrite/uuids")
+      assert resp.status_code == 200
+      assert length(resp.body["uuids"]) == 1
+    end
 
-        resp =
-          Rawresp.get(
-            
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView7/test/essai?doc=true"
-          )
+    @tag with_random_db: db_name
+    @tag config: [
+           {"chttpd", "rewrite_limit", "2"}
+         ]
+    test "loop detection on #{db_name}", context do
+      db_name = context[:db_name]
 
-        assert resp.status_code == 200
-        result = resp.body |> IO.iodata_to_binary() |> 
:jiffy.decode([:return_maps, :use_nil])
-        first_row = Enum.at(result["rows"], 0)
-        assert Map.has_key?(first_row, "doc")
+      ddoc_loop = %{
+        _id: "_design/loop",
+        rewrites: [%{from: "loop", to: "_rewrite/loop"}]
+      }
 
-        # COUCHDB-2031 - path normalization versus qs params
-        resp = 
Rawresp.get("/#{db_name}/_design/test/_rewrite/db/_design/test?meta=true")
-        assert resp.status_code == 200
-        result = resp.body |> IO.iodata_to_binary() |> 
:jiffy.decode([:return_maps, :use_nil])
-        assert result["_id"] == "_design/test"
-        assert Map.has_key?(result, "_revs_info")
-
-        ddoc2 = %{
-          _id: "_design/test2",
-          rewrites: [
-            %{
-              from: "uuids",
-              to: "../../../_uuids"
-            }
-          ]
-        }
+      create_doc(db_name, ddoc_loop)
 
-        create_doc(db_name, ddoc2)
-        resp = Couch.get("/#{db_name}/_design/test2/_rewrite/uuids")
-        assert resp.status_code == 500
-        assert resp.body["error"] == "insecure_rewrite_rule"
-      end
+      resp = Couch.get("/#{db_name}/_design/loop/_rewrite/loop")
+      assert resp.status_code == 400
+    end
 
-      @tag with_random_db: db_name
-      @tag config: [
-             {"chttpd", "secure_rewrites", "false"}
-           ]
-      test "path relative to server on #{db_name}", context do
-        db_name = context[:db_name]
-
-        ddoc = %{
-          _id: "_design/test2",
-          rewrites: [
-            %{
-              from: "uuids",
-              to: "../../../_uuids"
-            }
-          ]
-        }
+    @tag with_random_db: db_name
+    @tag config: [
+           {"chttpd", "rewrite_limit", "2"},
+           {"chttpd", "secure_rewrites", "false"}
+         ]
+    test "serial execution is not spuriously counted as loop on #{db_name}", 
context do
+      db_name = context[:db_name]
+
+      ddoc = %{
+        _id: "_design/test",
+        language: "javascript",
+        _attachments: %{
+          "foo.txt": %{
+            content_type: "text/plain",
+            data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
+          }
+        },
+        rewrites: [
+          %{
+            from: "foo",
+            to: "foo.txt"
+          }
+        ]
+      }
 
-        create_doc(db_name, ddoc)
+      create_doc(db_name, ddoc)
 
-        resp = Couch.get("/#{db_name}/_design/test2/_rewrite/uuids")
+      for _i <- 0..4 do
+        resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
         assert resp.status_code == 200
-        assert length(resp.body["uuids"]) == 1
-      end
-
-      @tag with_random_db: db_name
-      @tag config: [
-             {"chttpd", "rewrite_limit", "2"}
-           ]
-      test "loop detection on #{db_name}", context do
-        db_name = context[:db_name]
-
-        ddoc_loop = %{
-          _id: "_design/loop",
-          rewrites: [%{from: "loop", to: "_rewrite/loop"}]
-        }
-
-        create_doc(db_name, ddoc_loop)
-
-        resp = Couch.get("/#{db_name}/_design/loop/_rewrite/loop")
-        assert resp.status_code == 400
-      end
-
-      @tag with_random_db: db_name
-      @tag config: [
-             {"chttpd", "rewrite_limit", "2"},
-             {"chttpd", "secure_rewrites", "false"}
-           ]
-      test "serial execution is not spuriously counted as loop on #{db_name}", 
context do
-        db_name = context[:db_name]
-
-        ddoc = %{
-          _id: "_design/test",
-          language: "javascript",
-          _attachments: %{
-            "foo.txt": %{
-              content_type: "text/plain",
-              data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
-            }
-          },
-          rewrites: [
-            %{
-              from: "foo",
-              to: "foo.txt"
-            }
-          ]
-        }
-
-        create_doc(db_name, ddoc)
-
-        for _i <- 0..4 do
-          resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
-          assert resp.status_code == 200
-        end
       end
     end
-  )
+  end
 end

Reply via email to