summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2017-09-05 15:08:08 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2017-09-06 11:17:25 -0400
commitff6e5764c4d574fdd175f009cd7e35645d605a38 (patch)
tree53091c96baab16dce152f9b01932e8bf72072758
parent7284b684f3e3a223e67946bce45424b4e3d73a62 (diff)
downloadcouchdb-ff6e5764c4d574fdd175f009cd7e35645d605a38.tar.gz
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
-rw-r--r--src/couch_mrview/src/couch_mrview.erl8
-rw-r--r--src/couch_mrview/test/couch_mrview_ddoc_validation_tests.erl59
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 c44dd91f3..11c209b43 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 028e0be11..c2038ddfb 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, _},