diff options
-rw-r--r-- | share/www/script/test/list_views.js | 44 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_show.erl | 8 |
2 files changed, 45 insertions, 7 deletions
diff --git a/share/www/script/test/list_views.js b/share/www/script/test/list_views.js index b261be71..e31f0f83 100644 --- a/share/www/script/test/list_views.js +++ b/share/www/script/test/list_views.js @@ -177,6 +177,23 @@ couchTests.list_views = function(debug) { } } }; + var erlListDoc = { + _id: "_design/erlang", + language: "erlang", + lists: { + simple: + 'fun(Head, {Req}) -> ' + + ' Send(<<"[">>), ' + + ' Fun = fun({Row}, Sep) -> ' + + ' Val = proplists:get_value(<<"key">>, Row, 23), ' + + ' Send(list_to_binary(Sep ++ integer_to_list(Val))), ' + + ' {ok, ","} ' + + ' end, ' + + ' {ok, _} = FoldRows(Fun, ""), ' + + ' Send(<<"]">>) ' + + 'end.' + } + }; T(db.save(designDoc).ok); @@ -373,10 +390,33 @@ couchTests.list_views = function(debug) { // Test we can run lists and views from separate docs. T(db.save(viewOnlyDesignDoc).ok); - xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/views/basicView?startkey=-3"); - T(xhr.status == 200, "with query params"); + var url = "/test_suite_db/_design/lists/_list/simpleForm/views/basicView" + + "?startkey=-3"; + xhr = CouchDB.request("GET", url); + T(xhr.status == 200, "multiple design docs."); T(/Total Rows/.test(xhr.responseText)); T(!(/Key: -4/.test(xhr.responseText))); T(/FirstKey: -3/.test(xhr.responseText)); T(/LastKey: 0/.test(xhr.responseText)); + + var erlViewTest = function() { + T(db.save(erlListDoc).ok); + var url = "/test_suite_db/_design/erlang/_list/simple/views/basicView" + + "?startkey=-3"; + xhr = CouchDB.request("GET", url); + T(xhr.status == 200, "multiple languages in design docs."); + var list = JSON.parse(xhr.responseText); + T(list.length == 4); + for(var i = 0; i < list.length; i++) + { + T(list[i] + 3 == i); + } + }; + + run_on_modified_server([{ + section: "native_query_servers", + key: "erlang", + value: "{couch_native_process, start_link, []}" + }], erlViewTest); + }; diff --git a/src/couchdb/couch_httpd_show.erl b/src/couchdb/couch_httpd_show.erl index 3aa6b566..a961033a 100644 --- a/src/couchdb/couch_httpd_show.erl +++ b/src/couchdb/couch_httpd_show.erl @@ -124,16 +124,14 @@ handle_view_list(Req, ListDesignName, ListName, ViewDesignName, ViewName, Db, Ke #doc{body={ListProps}} = couch_httpd_db:couch_doc_open(Db, ListDesignId, nil, []), if ViewDesignName == ListDesignName -> - ViewProps = ListProps, ViewDesignId = ListDesignId; true -> - ViewDesignId = <<"_design/", ViewDesignName/binary>>, - #doc{body={ViewProps}} = couch_httpd_db:couch_doc_open(Db, ViewDesignId, nil, []) + ViewDesignId = <<"_design/", ViewDesignName/binary>> end, - ViewLang = proplists:get_value(<<"language">>, ViewProps, <<"javascript">>), + ListLang = proplists:get_value(<<"language">>, ListProps, <<"javascript">>), ListSrc = couch_util:get_nested_json_value({ListProps}, [<<"lists">>, ListName]), - send_view_list_response(ViewLang, ListSrc, ViewName, ViewDesignId, Req, Db, Keys). + send_view_list_response(ListLang, ListSrc, ViewName, ViewDesignId, Req, Db, Keys). send_view_list_response(Lang, ListSrc, ViewName, DesignId, Req, Db, Keys) -> |