summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rw-r--r--share/server/loop.js1
-rw-r--r--share/server/state.js7
-rw-r--r--share/www/script/test/design_docs.js19
3 files changed, 24 insertions, 3 deletions
diff --git a/share/server/loop.js b/share/server/loop.js
index 300151e9..d5bbd977 100644
--- a/share/server/loop.js
+++ b/share/server/loop.js
@@ -100,6 +100,7 @@ var Loop = function() {
// "view" : Views.handler,
"reset" : State.reset,
"add_fun" : State.addFun,
+ "add_lib" : State.addLib,
"map_doc" : Views.mapDoc,
"reduce" : Views.reduce,
"rereduce" : Views.rereduce
diff --git a/share/server/state.js b/share/server/state.js
index 9af9e475..e6416382 100644
--- a/share/server/state.js
+++ b/share/server/state.js
@@ -14,6 +14,7 @@ var State = {
reset : function(config) {
// clear the globals and run gc
State.funs = [];
+ State.lib = null;
State.query_config = config || {};
init_sandbox();
gc();
@@ -21,7 +22,11 @@ var State = {
},
addFun : function(newFun) {
// Compile to a function and add it to funs array
- State.funs.push(Couch.compileFunction(newFun));
+ State.funs.push(Couch.compileFunction(newFun, {views : {lib : State.lib}}));
+ print("true");
+ },
+ addLib : function(lib) {
+ State.lib = lib;
print("true");
}
}
diff --git a/share/www/script/test/design_docs.js b/share/www/script/test/design_docs.js
index 8864225c..62606341 100644
--- a/share/www/script/test/design_docs.js
+++ b/share/www/script/test/design_docs.js
@@ -54,7 +54,18 @@ function() {
summate2: {map:"function (doc) {emit(doc.integer, doc.integer)};",
reduce:"function (keys, values) { return sum(values); };"},
huge_src_and_results: {map: "function(doc) { if (doc._id == \"1\") { emit(\"" + makebigstring(16) + "\", null) }}",
- reduce:"function (keys, values) { return \"" + makebigstring(16) + "\"; };"}
+ reduce:"function (keys, values) { return \"" + makebigstring(16) + "\"; };"},
+ lib : {
+ baz : "exports.baz = 'bam';",
+ foo : {
+ foo : "exports.foo = 'bar';",
+ boom : "exports.boom = 'ok';",
+ zoom : "exports.zoom = 'yeah';"
+ }
+ },
+ commonjs : {
+ map : "function(doc) { emit(null, require('views/lib/foo/boom').boom)}"
+ }
},
shows: {
simple: "function() {return 'ok'};",
@@ -99,10 +110,14 @@ function() {
var vinfo = dinfo.view_index;
TEquals(51, vinfo.disk_size);
TEquals(false, vinfo.compact_running);
- TEquals("3f88e53b303e2342e49a66c538c30679", vinfo.signature);
+ TEquals("dc3264b45b74cc6d94666e3043e07154", vinfo.signature, 'ddoc sig');
db.bulkSave(makeDocs(1, numDocs + 1));
+ // test commonjs in map functions
+ resp = db.view("test/commonjs", {limit:1});
+ T(resp.rows[0].value == 'ok');
+
// test that the _all_docs view returns correctly with keys
var results = db.allDocs({startkey:"_design", endkey:"_design0"});
T(results.rows.length == 1);