couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [02/50] [abbrv] couchdb-mango git commit: Correctly set the ddoc language on recreation
Date Tue, 03 Feb 2015 15:13:09 GMT
Correctly set the ddoc language on recreation

If a design document was recreated it wasn't properly setting the
language elment which defaults to JavaScript. This lead to issues with
operations that appeared to succeed but actually failed behind the
scenes.

BugzId: 31919


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mango/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mango/commit/2744ddfd
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/2744ddfd
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/2744ddfd

Branch: refs/heads/master
Commit: 2744ddfd9e72cb36d5fb463d3c3fd387d3c6bfb4
Parents: 83fb0db
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Tue Jun 24 14:58:17 2014 -0500
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Tue Jun 24 14:58:17 2014 -0500

----------------------------------------------------------------------
 src/mango_error.erl        |  7 +++++++
 src/mango_util.erl         | 16 +++++++++++++++-
 test/01-index-crud-test.py | 16 ++++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2744ddfd/src/mango_error.erl
----------------------------------------------------------------------
diff --git a/src/mango_error.erl b/src/mango_error.erl
index f34dac5..45ffe56 100644
--- a/src/mango_error.erl
+++ b/src/mango_error.erl
@@ -216,6 +216,13 @@ info(mango_sort, {unsupported, mixed_sort}) ->
         <<"Sorts currently only support a single direction for all fields.">>
     };
 
+info(mango_util, {invalid_ddoc_lang, Lang}) ->
+    {
+        400,
+        <<"invalid_ddoc_lang">>,
+        fmt("Existing design doc has an invalid language: ~w", [Lang])
+    };
+
 info(Module, Reason) ->
     {
         500,

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2744ddfd/src/mango_util.erl
----------------------------------------------------------------------
diff --git a/src/mango_util.erl b/src/mango_util.erl
index d3dd279..ff7d654 100644
--- a/src/mango_util.erl
+++ b/src/mango_util.erl
@@ -49,7 +49,7 @@ open_ddocs(Db) ->
 load_ddoc(Db, DDocId) ->
     case mango_util:open_doc(Db, DDocId) of
         {ok, Doc} ->
-            {ok, Doc};
+            {ok, check_lang(Doc)};
         not_found ->
             Body = {[
                 {<<"language">>, <<"query">>}
@@ -135,6 +135,20 @@ assert_ejson_arr([Val | Rest]) ->
     end.
 
 
+check_lang(#doc{id = Id, deleted = true} = Doc) ->
+    Body = {[
+        {<<"language">>, <<"query">>}
+    ]},
+    #doc{id = Id, body = Body};
+check_lang(#doc{body = {Props}} = Doc) ->
+    case lists:keyfind(<<"language">>, 1, Props) of
+        {<<"language">>, <<"query">>} ->
+            Doc;
+        Else ->
+            ?MANGO_ERROR({invalid_ddoc_lang, Else})
+    end.
+
+
 to_lower(Key) when is_binary(Key) ->
     KStr = binary_to_list(Key),
     KLower = string:to_lower(KStr),

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2744ddfd/test/01-index-crud-test.py
----------------------------------------------------------------------
diff --git a/test/01-index-crud-test.py b/test/01-index-crud-test.py
index 35b1301..b6ef786 100644
--- a/test/01-index-crud-test.py
+++ b/test/01-index-crud-test.py
@@ -170,6 +170,22 @@ def test_delete_idx_no_design():
     assert pre_indexes == post_indexes
 
 
+def test_recreate_index():
+    db = mkdb()
+    pre_indexes = db.list_indexes()
+    for i in range(5):
+        ret = db.create_index(["bing"], name="idx_recreate")
+        assert ret is True
+        for idx in db.list_indexes():
+            if idx["name"] != "idx_recreate":
+                continue
+            assert idx["def"]["fields"] == [{"bing": "asc"}]
+            db.delete_index(idx["ddoc"], idx["name"])
+            break
+        post_indexes = db.list_indexes()
+        assert pre_indexes == post_indexes
+
+
 def test_delete_misisng():
     db = mkdb()
 


Mime
View raw message