summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/server/main.js7
-rw-r--r--share/www/script/couch_tests.js87
-rwxr-xr-xtest/runner.sh2
-rw-r--r--test/test.js3
4 files changed, 52 insertions, 47 deletions
diff --git a/share/server/main.js b/share/server/main.js
index 58acae90..dfb0a403 100644
--- a/share/server/main.js
+++ b/share/server/main.js
@@ -133,7 +133,6 @@ var Mimeparse = (function() {
return publicMethods;
})();
-
// this function provides a shortcut for managing responses by Accept header
respondWith = function(req, responders) {
var accept = req.headers["Accept"];
@@ -153,9 +152,9 @@ respondWith = function(req, responders) {
resp["headers"]["Content-Type"] = bestMime;
return resp;
}
- }
- if (responders.default) {
- return responders[responders.default]();
+ }
+ if (responders.fallback) {
+ return responders[responders.fallback]();
}
throw({code:406, body:"Not Acceptable: "+accept});
}
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js
index 5a642f33..c0f909ad 100644
--- a/share/www/script/couch_tests.js
+++ b/share/www/script/couch_tests.js
@@ -2034,43 +2034,49 @@ var tests = {
db.deleteDb();
db.createDb();
if (debug) debugger;
+
+ function stringFun(fun) {
+ var string = fun.toSource ? fun.toSource() : "(" + fun.toString() + ")";
+ return string;
+ }
var designDoc = {
_id:"_design/template",
language: "javascript",
forms: {
- "hello" : (function() {
+ "hello" : stringFun(function() {
return {
body : "Hello World"
};
- }).toString(),
- "just-name" : (function(doc, req) {
+ }),
+ "just-name" : stringFun(function(doc, req) {
return {
body : "Just " + doc.name
};
- }).toString(),
- "req-info" : (function(doc, req) {
+ }),
+ "req-info" : stringFun(function(doc, req) {
return {
json : req
}
- }).toString(),
- "xml-type" : (function(doc, req) {
- return {
- headers : {
- "Content-Type" : "application/xml"
- },
- "body" : <xml><node foo="bar"/></xml>
- }
- }).toString(),
- "no-set-etag" : (function(doc, req) {
+ }),
+ "xml-type" : [
+ 'function(doc, req) { ',
+ ' return { ',
+ ' "headers" : { ',
+ ' "Content-Type" : "application/xml" ',
+ ' }, ',
+ ' "body" : <xml><node foo="bar"/></xml>',
+ ' } ',
+ '}'].join('\n'),
+ "no-set-etag" : stringFun(function(doc, req) {
return {
headers : {
"Etag" : "skipped"
},
"body" : "something"
}
- }).toString(),
- "accept-switch" : (function(doc, req) {
+ }),
+ "accept-switch" : stringFun(function(doc, req) {
if (req.headers["Accept"].match(/image/)) {
return {
// a 16x16 px version of the CouchDB logo
@@ -2097,29 +2103,30 @@ var tests = {
}
};
}
- }).toString(),
- "respondWith" : (function(doc, req) {
- registerType("foo", "application/foo","application/x-foo");
- return respondWith(req, {
- html : function() {
- return {
- body:"Ha ha, you said \"" + doc.word + "\"."
- };
- },
- xml : function() {
- return {
- body: <xml><node foo={doc.word}/></xml>
- };
- },
- foo : function() {
- return {
- body: "foofoo"
- };
- },
- default : "html"
- });
- }).toString()
- }
+ }),
+ "respondWith" : [
+ 'function(doc, req) { ',
+ ' registerType("foo", "application/foo","application/x-foo");',
+ ' return respondWith(req, { ',
+ ' html : function() { ',
+ ' return { ',
+ ' body:"Ha ha, you said \\"" + doc.word + "\\"." ',
+ ' }; ',
+ ' }, ',
+ ' xml : function() { ',
+ ' return { ',
+ ' body: <xml><node foo={doc.word}/></xml> ',
+ ' }; ',
+ ' }, ',
+ ' foo : function() { ',
+ ' return { ',
+ ' body: "foofoo" ',
+ ' }; ',
+ ' }, ',
+ ' fallback : "html" ',
+ ' }); ',
+ '}'].join('\n')
+ }
};
T(db.save(designDoc).ok);
diff --git a/test/runner.sh b/test/runner.sh
index e920090d..561110a8 100755
--- a/test/runner.sh
+++ b/test/runner.sh
@@ -4,4 +4,4 @@ erlc runner.erl
erl -noshell -pa ../src/couchdb -pa ../src/mochiweb -eval "runner:run()"
-cat ../share/www/script/couch.js ../share/www/script/couch_tests.js test.js | ../src/couchdb/couchjs -
+cat ../share/www/script/couch.js ../share/www/script/couch_test_runner.js ../share/www/script/couch_tests.js test.js | ../src/couchdb/couchjs -
diff --git a/test/test.js b/test/test.js
index e47153bd..a4aa32e1 100644
--- a/test/test.js
+++ b/test/test.js
@@ -67,8 +67,7 @@ var HTTP = (function() {
var h = headers[i];
if (keymatcher.test(h)) {
var value = h.substr(key.length+2);
- value = value.slice(0, value.length-1);
- return value;
+ return value.replace(/^\s+|\s+$/g,"");
}
}
return "";