summaryrefslogtreecommitdiff
path: root/share/www/script/test
diff options
context:
space:
mode:
authorPaul Joseph Davis <davisp@apache.org>2009-08-21 22:11:17 +0000
committerPaul Joseph Davis <davisp@apache.org>2009-08-21 22:11:17 +0000
commit4143b6805cddf61dfd0d43b712b598705bca1933 (patch)
tree57681015cfd6b9731386df9d052b9243796513b7 /share/www/script/test
parent678512dcabec2a54071ed63ed786c4c0c3f1d647 (diff)
Munge all ErlJSON to use binaries.
Our flavor of ErlJSON has this interesting characteristic: {[{foo, bar}]} == {[{<<"foo">>, <<"bar">>}]} This is fine and dandy for writing ErlJSON that is going to go directly to a serializer, but when it goes to client code executing in couch_native_process.erl it becomes a pain in the but to know whether to use atoms or binaries. This patch munges all input to user functions to use binaries except for null, true, and false obviously. This fixes the commented out test in erlang_views.js as well as adds a show to poke into the request object that has known instances of where things get munged. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@806732 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script/test')
-rw-r--r--share/www/script/test/erlang_views.js29
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");
- ***/
});
};