diff options
Diffstat (limited to 'share/www')
-rw-r--r-- | share/www/script/couch.js | 4 | ||||
-rw-r--r-- | share/www/script/couch_tests.js | 1 | ||||
-rw-r--r-- | share/www/script/futon.browse.js | 58 | ||||
-rw-r--r-- | share/www/script/test/changes.js | 8 | ||||
-rw-r--r-- | share/www/script/test/erlang_views.js | 82 |
5 files changed, 126 insertions, 27 deletions
diff --git a/share/www/script/couch.js b/share/www/script/couch.js index af3bb8fb..eba60ad5 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -127,8 +127,8 @@ function CouchDB(name, httpHeaders) { } // Applies the map function to the contents of database and returns the results. - this.query = function(mapFun, reduceFun, options, keys) { - var body = {language: "javascript"}; + this.query = function(mapFun, reduceFun, options, keys, language) { + var body = {language: language || "javascript"}; if(keys) { body.keys = keys ; } diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 3d415952..7ddfa312 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -81,6 +81,7 @@ loadScript("script/oauth.js"); loadTest("oauth.js"); loadTest("stats.js"); loadTest("rev_stemming.js"); +loadTest("erlang_views.js"); function makeDocs(start, end, templateDoc) { var templateDocSrc = templateDoc ? JSON.stringify(templateDoc) : "{}" diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js index 29c0d86a..7fa880fd 100644 --- a/share/www/script/futon.browse.js +++ b/share/www/script/futon.browse.js @@ -206,32 +206,48 @@ // Populate the languages dropdown, and listen to selection changes this.populateLanguagesMenu = function() { + var all_langs = {}; + fill_language = function() { + var select = $("#language"); + for (var language in all_langs) { + var option = $(document.createElement("option")) + .attr("value", language).text(language) + .appendTo(select); + } + if (select[0].options.length == 1) { + select[0].disabled = true; + } else { + select[0].disabled = false; + select.val(page.viewLanguage); + select.change(function() { + var language = $("#language").val(); + if (language != page.viewLanguage) { + var mapFun = $("#viewcode_map").val(); + if (mapFun == "" || mapFun == templates[page.viewLanguage]) { + // no edits made, so change to the new default + $("#viewcode_map").val(templates[language]); + } + page.viewLanguage = language; + $("#viewcode_map")[0].focus(); + } + return false; + }); + } + } $.couch.config({ success: function(resp) { - var select = $("#language"); for (var language in resp) { - var option = $(document.createElement("option")) - .attr("value", language).text(language) - .appendTo(select); + all_langs[language] = resp[language]; } - if (select[0].options.length == 1) { - select[0].disabled = true; - } else { - select.val(page.viewLanguage); - select.change(function() { - var language = $("#language").val(); - if (language != page.viewLanguage) { - var mapFun = $("#viewcode_map").val(); - if (mapFun == "" || mapFun == templates[page.viewLanguage]) { - // no edits made, so change to the new default - $("#viewcode_map").val(templates[language]); - } - page.viewLanguage = language; - $("#viewcode_map")[0].focus(); + + $.couch.config({ + success: function(resp) { + for (var language in resp) { + all_langs[language] = resp[language]; } - return false; - }); - } + fill_language(); + } + }, "native_query_servers"); } }, "query_servers"); } diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js index d8abcc71..393ff034 100644 --- a/share/www/script/test/changes.js +++ b/share/www/script/test/changes.js @@ -161,13 +161,13 @@ couchTests.changes = function(debug) { var ddoc = { _id : "_design/changes_filter", "filters" : { - "bop" : "function(doc, req, userCtx) { return (doc.bop);}", - "dynamic" : stringFun(function(doc, req, userCtx) { + "bop" : "function(doc, req) { return (doc.bop);}", + "dynamic" : stringFun(function(doc, req) { var field = req.query.field; return doc[field]; }), - "userCtx" : stringFun(function(doc, req, userCtx) { - return doc.user && (doc.user == userCtx.name); + "userCtx" : stringFun(function(doc, req) { + return doc.user && (doc.user == req.userCtx.name); }) } } diff --git a/share/www/script/test/erlang_views.js b/share/www/script/test/erlang_views.js new file mode 100644 index 00000000..6a378690 --- /dev/null +++ b/share/www/script/test/erlang_views.js @@ -0,0 +1,82 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +couchTests.erlang_views = function(debug) { + var db = new CouchDB("test_suite_db"); + db.deleteDb(); + db.createDb(); + if (debug) debugger; + + + + run_on_modified_server( + [{section: "native_query_servers", + key: "erlang", + value: "{couch_native_process, start_link, []}"}], + 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]}; + T(db.save(doc).ok); + + var mfun = 'fun({Doc}) -> ' + + ' K = proplists:get_value(<<"integer">>, Doc, null), ' + + ' V = proplists:get_value(<<"string">>, Doc, null), ' + + ' Emit(K, V) ' + + 'end.'; + + // emitting a key value that is undefined should result in that row not + // being included in the view results + var results = db.query(mfun, null, null, null, "erlang"); + 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"}; + T(db.save(doc).ok); + rfun = "fun(Keys, Values, ReReduce) -> length(Values) end." + results = db.query(mfun, rfun, null, null, "erlang"); + T(results.rows[0].value == 2); + + // simple 'list' tests + var designDoc = { + _id:"_design/erlview", + language: "erlang", + lists: { + simple_list : + 'fun(Head, {Req}) -> ' + + ' Send(<<"head">>), ' + + ' Fun = fun({Row}, _) -> ' + + ' Send(proplists:get_value(<<"value">>, Row, null)), ' + + ' {ok, nil} ' + + ' end, ' + + ' {ok, _} = FoldRows(Fun, nil), ' + + ' <<"tail">> ' + + 'end. ' + }, + views: { + simple_view : { + map: mfun, + reduce: rfun + } + } + }; + 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"); + T(xhr.status == 200, "standard get should be 200"); + T(xhr.responseText == "head2tail"); + ***/ + }); +}; |