diff options
Diffstat (limited to 'share')
-rw-r--r-- | share/www/script/test/erlang_views.js | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/share/www/script/test/erlang_views.js b/share/www/script/test/erlang_views.js index 24f6cd1a..2af26b5a 100644 --- a/share/www/script/test/erlang_views.js +++ b/share/www/script/test/erlang_views.js @@ -25,7 +25,7 @@ couchTests.erlang_views = function(debug) { function() { // Note we just do some basic 'smoke tests' here - the // test/query_server_spec.rb tests have more comprehensive tests - var doc = {integer: 1, string: "str1", array: [1, 2, 3]}; + var doc = {_id: "1", integer: 1, string: "str1", array: [1, 2, 3]}; T(db.save(doc).ok); var mfun = 'fun({Doc}) -> ' + @@ -40,8 +40,9 @@ couchTests.erlang_views = function(debug) { T(results.total_rows == 1); T(results.rows[0].key == 1); T(results.rows[0].value == "str1"); + // check simple reduction - another doc with same key. - var doc = {integer: 1, string: "str2"}; + var doc = {_id: "2", integer: 1, string: "str2"}; T(db.save(doc).ok); rfun = "fun(Keys, Values, ReReduce) -> length(Values) end." results = db.query(mfun, rfun, null, null, "erlang"); @@ -51,12 +52,23 @@ couchTests.erlang_views = function(debug) { var designDoc = { _id:"_design/erlview", language: "erlang", + shows: { + simple: + 'fun(Doc, {Req}) -> ' + + ' {Info} = proplists:get_value(<<"info">>, Req, {[]}), ' + + ' Purged = proplists:get_value(<<"purge_seq">>, Info, -1), ' + + ' Verb = proplists:get_value(<<"verb">>, Req, <<"not_get">>), ' + + ' R = list_to_binary(io_lib:format("~b - ~s", [Purged, Verb])), ' + + ' {[{<<"code">>, 200}, {<<"headers">>, {[]}}, {<<"body">>, R}]} ' + + 'end.' + }, lists: { simple_list : 'fun(Head, {Req}) -> ' + ' Send(<<"head">>), ' + ' Fun = fun({Row}, _) -> ' + - ' Send(proplists:get_value(<<"value">>, Row, null)), ' + + ' Val = proplists:get_value(<<"value">>, Row, -1), ' + + ' Send(list_to_binary(integer_to_list(Val))), ' + ' {ok, nil} ' + ' end, ' + ' {ok, _} = FoldRows(Fun, nil), ' + @@ -72,11 +84,14 @@ couchTests.erlang_views = function(debug) { }; T(db.save(designDoc).ok); - // *sob* - show functions have problems :( - /*** - var xhr = CouchDB.request("GET", "/test_suite_db/_design/erlview/_list/simple_list/simple_view"); + var url = "/test_suite_db/_design/erlview/_show/simple/1"; + var xhr = CouchDB.request("GET", url); + T(xhr.status == 200, "standard get should be 200"); + T(xhr.responseText == "0 - GET"); + + var url = "/test_suite_db/_design/erlview/_list/simple_list/simple_view"; + var xhr = CouchDB.request("GET", url); T(xhr.status == 200, "standard get should be 200"); T(xhr.responseText == "head2tail"); - ***/ }); }; |