You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2017/09/06 15:17:28 UTC

[couchdb] branch master updated: Allow library object in other design doc sections besides views

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

vatamane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new ff6e576  Allow library object in other design doc sections besides views
ff6e576 is described below

commit ff6e5764c4d574fdd175f009cd7e35645d605a38
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Tue Sep 5 15:08:08 2017 -0400

    Allow library object in other design doc sections besides views
    
    Previously only `views` sections could have a `lib` object. But some users
    might choose to have a library for filters for example.
    
    This makes it agree with this section of the wiki:
    
    https://wiki.apache.org/couchdb/CommonJS_Modules
---
 src/couch_mrview/src/couch_mrview.erl              |  8 +--
 .../test/couch_mrview_ddoc_validation_tests.erl    | 59 +++++++++++++++++-----
 2 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl
index c44dd91..11c209b 100644
--- a/src/couch_mrview/src/couch_mrview.erl
+++ b/src/couch_mrview/src/couch_mrview.erl
@@ -52,13 +52,13 @@ validate_ddoc_fields(DDoc) ->
     lists:foreach(fun(Path) ->
         validate_ddoc_fields(DDoc, Path)
     end, [
-        [{<<"filters">>, object}, {any, string}],
+        [{<<"filters">>, object}, {any, [object, string]}],
         [{<<"language">>, string}],
-        [{<<"lists">>, object}, {any, string}],
+        [{<<"lists">>, object}, {any, [object, string]}],
         [{<<"options">>, object}],
         [{<<"rewrites">>, [string, array]}],
-        [{<<"shows">>, object}, {any, string}],
-        [{<<"updates">>, object}, {any, string}],
+        [{<<"shows">>, object}, {any, [object, string]}],
+        [{<<"updates">>, object}, {any, [object, string]}],
         [{<<"validate_doc_update">>, string}],
         [{<<"views">>, object}, {<<"lib">>, object}],
         [{<<"views">>, object}, {any, object}, {<<"map">>, MapFuncType}],
diff --git a/src/couch_mrview/test/couch_mrview_ddoc_validation_tests.erl b/src/couch_mrview/test/couch_mrview_ddoc_validation_tests.erl
index 028e0be..c2038dd 100644
--- a/src/couch_mrview/test/couch_mrview_ddoc_validation_tests.erl
+++ b/src/couch_mrview/test/couch_mrview_ddoc_validation_tests.erl
@@ -15,6 +15,8 @@
 -include_lib("couch/include/couch_eunit.hrl").
 -include_lib("couch/include/couch_db.hrl").
 
+-define(LIB, {[{<<"mylib">>, {[{<<"lib1">>, <<"x=42">>}]}}]}).
+
 setup() ->
     {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), map),
     Db.
@@ -39,9 +41,13 @@ ddoc_validation_test_() ->
                     fun should_reject_invalid_builtin_reduce/1,
                     fun should_reject_non_object_options/1,
                     fun should_reject_non_object_filters/1,
+                    fun should_accept_obj_in_filters/1,
                     fun should_reject_non_object_lists/1,
+                    fun should_accept_obj_in_lists/1,
                     fun should_reject_non_object_shows/1,
+                    fun should_accept_obj_in_shows/1,
                     fun should_reject_non_object_updates/1,
+                    fun should_accept_obj_in_updates/1,
                     fun should_reject_non_object_views/1,
                     fun should_reject_non_string_language/1,
                     fun should_reject_non_string_validate_doc_update/1,
@@ -50,13 +56,13 @@ ddoc_validation_test_() ->
                     fun should_accept_option/1,
                     fun should_accept_any_option/1,
                     fun should_accept_filter/1,
-                    fun should_reject_non_string_filter_function/1,
+                    fun should_reject_non_string_or_obj_filter_function/1,
                     fun should_accept_list/1,
-                    fun should_reject_non_string_list_function/1,
+                    fun should_reject_non_string_or_obj_list_function/1,
                     fun should_accept_show/1,
-                    fun should_reject_non_string_show_function/1,
+                    fun should_reject_non_string_or_obj_show_function/1,
                     fun should_accept_update/1,
-                    fun should_reject_non_string_update_function/1,
+                    fun should_reject_non_string_or_obj_update_function/1,
                     fun should_accept_view/1,
                     fun should_accept_view_with_reduce/1,
                     fun should_accept_view_with_lib/1,
@@ -129,6 +135,13 @@ should_reject_non_object_filters(Db) ->
     ?_assertThrow({bad_request, invalid_design_doc, _},
                   couch_db:update_doc(Db, Doc, [])).
 
+should_accept_obj_in_filters(Db) ->
+    Doc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/should_accept_obj_in_filters">>},
+        {<<"filters">>, ?LIB}
+    ]}),
+    ?_assertMatch({ok, _}, couch_db:update_doc(Db, Doc, [])).
+
 should_reject_non_object_lists(Db) ->
     Doc = couch_doc:from_json_obj({[
         {<<"_id">>, <<"_design/should_reject_non_object_lists">>},
@@ -145,6 +158,13 @@ should_reject_non_object_shows(Db) ->
     ?_assertThrow({bad_request, invalid_design_doc, _},
                   couch_db:update_doc(Db, Doc, [])).
 
+should_accept_obj_in_shows(Db) ->
+    Doc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/should_accept_obj_in_shows">>},
+        {<<"shows">>, ?LIB}
+    ]}),
+    ?_assertMatch({ok, _}, couch_db:update_doc(Db, Doc, [])).
+
 should_reject_non_object_updates(Db) ->
     Doc = couch_doc:from_json_obj({[
         {<<"_id">>, <<"_design/should_reject_non_object_updates">>},
@@ -153,6 +173,13 @@ should_reject_non_object_updates(Db) ->
     ?_assertThrow({bad_request, invalid_design_doc, _},
                   couch_db:update_doc(Db, Doc, [])).
 
+should_accept_obj_in_updates(Db) ->
+    Doc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/should_accept_obj_in_updates">>},
+        {<<"updates">>, ?LIB}
+    ]}),
+    ?_assertMatch({ok, _}, couch_db:update_doc(Db, Doc, [])).
+
 should_reject_non_object_views(Db) ->
     Doc = couch_doc:from_json_obj({[
         {<<"_id">>, <<"_design/should_reject_non_object_views">>},
@@ -213,9 +240,9 @@ should_accept_filter(Db) ->
     ]}),
     ?_assertMatch({ok,_}, couch_db:update_doc(Db, Doc, [])).
 
-should_reject_non_string_filter_function(Db) ->
+should_reject_non_string_or_obj_filter_function(Db) ->
     Doc = couch_doc:from_json_obj({[
-        {<<"_id">>, <<"_design/should_reject_non_string_filter_function">>},
+        {<<"_id">>, <<"_design/should_reject_non_string_or_obj_filter_function">>},
         {<<"filters">>, {[ {<<"filter1">>, 1} ]}}
     ]}),
     ?_assertThrow({bad_request, invalid_design_doc, _},
@@ -228,14 +255,22 @@ should_accept_list(Db) ->
     ]}),
     ?_assertMatch({ok,_}, couch_db:update_doc(Db, Doc, [])).
 
-should_reject_non_string_list_function(Db) ->
+should_reject_non_string_or_obj_list_function(Db) ->
     Doc = couch_doc:from_json_obj({[
-        {<<"_id">>, <<"_design/should_reject_non_string_list_function">>},
+        {<<"_id">>, <<"_design/should_reject_non_string_or_obj_list_function">>},
         {<<"lists">>, {[ {<<"list1">>, 1} ]}}
     ]}),
     ?_assertThrow({bad_request, invalid_design_doc, _},
                   couch_db:update_doc(Db, Doc, [])).
 
+should_accept_obj_in_lists(Db) ->
+    Doc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/should_accept_obj_in_lists">>},
+        {<<"lists">>, ?LIB}
+    ]}),
+    ?_assertMatch({ok, _}, couch_db:update_doc(Db, Doc, [])).
+
+
 should_accept_show(Db) ->
     Doc = couch_doc:from_json_obj({[
         {<<"_id">>, <<"_design/should_accept_shows">>},
@@ -243,9 +278,9 @@ should_accept_show(Db) ->
     ]}),
     ?_assertMatch({ok,_}, couch_db:update_doc(Db, Doc, [])).
 
-should_reject_non_string_show_function(Db) ->
+should_reject_non_string_or_obj_show_function(Db) ->
     Doc = couch_doc:from_json_obj({[
-        {<<"_id">>, <<"_design/should_reject_non_string_show_function">>},
+        {<<"_id">>, <<"_design/should_reject_non_string_or_obj_show_function">>},
         {<<"shows">>, {[ {<<"show1">>, 1} ]}}
     ]}),
     ?_assertThrow({bad_request, invalid_design_doc, _},
@@ -258,9 +293,9 @@ should_accept_update(Db) ->
     ]}),
     ?_assertMatch({ok,_}, couch_db:update_doc(Db, Doc, [])).
 
-should_reject_non_string_update_function(Db) ->
+should_reject_non_string_or_obj_update_function(Db) ->
     Doc = couch_doc:from_json_obj({[
-        {<<"_id">>, <<"_design/should_reject_non_string_update_function">>},
+        {<<"_id">>, <<"_design/should_reject_non_string_or_obj_update_function">>},
         {<<"updates">>, {[ {<<"update1">>, 1} ]}}
     ]}),
     ?_assertThrow({bad_request, invalid_design_doc, _},

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].