summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/www/script/test/erlang_views.js29
-rw-r--r--src/couchdb/couch_native_process.erl20
-rwxr-xr-x[-rw-r--r--]test/run_native_process.es0
3 files changed, 41 insertions, 8 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");
- ***/
});
};
diff --git a/src/couchdb/couch_native_process.erl b/src/couchdb/couch_native_process.erl
index df879633..65b733bf 100644
--- a/src/couchdb/couch_native_process.erl
+++ b/src/couchdb/couch_native_process.erl
@@ -81,7 +81,7 @@ prompt(Pid, Data) when is_pid(Pid), is_list(Data) ->
_ ->
ok % Not listing
end,
- {NewState, Resp} = run(State, Data),
+ {NewState, Resp} = run(State, to_binary(Data)),
put(?STATE, NewState),
case Resp of
{error, Reason} ->
@@ -345,3 +345,21 @@ start_list_resp(Self, Sig) ->
_ ->
ok
end.
+
+to_binary({Data}) ->
+ Pred = fun({Key, Value}) ->
+ {to_binary(Key), to_binary(Value)}
+ end,
+ {lists:map(Pred, Data)};
+to_binary(Data) when is_list(Data) ->
+ lists:map(fun to_binary/1, Data);
+to_binary(null) ->
+ null;
+to_binary(true) ->
+ true;
+to_binary(false) ->
+ false;
+to_binary(Data) when is_atom(Data) ->
+ list_to_binary(atom_to_list(Data));
+to_binary(Data) ->
+ Data.
diff --git a/test/run_native_process.es b/test/run_native_process.es
index dfdc423e..dfdc423e 100644..100755
--- a/test/run_native_process.es
+++ b/test/run_native_process.es