summaryrefslogtreecommitdiff
path: root/share/www/script/test
diff options
context:
space:
mode:
Diffstat (limited to 'share/www/script/test')
-rw-r--r--share/www/script/test/list_views.js73
-rw-r--r--share/www/script/test/show_documents.js59
2 files changed, 67 insertions, 65 deletions
diff --git a/share/www/script/test/list_views.js b/share/www/script/test/list_views.js
index 4b089bac..5871e10e 100644
--- a/share/www/script/test/list_views.js
+++ b/share/www/script/test/list_views.js
@@ -83,34 +83,33 @@ couchTests.list_views = function(debug) {
}),
acceptSwitch: stringFun(function(head, req) {
// respondWith takes care of setting the proper headers
- respondWith(req, {
- html : function() {
- send("HTML <ul>");
-
- var row, num = 0;
- while (row = getRow()) {
- num ++;
- send('\n<li>Key: '
- +row.key+' Value: '+row.value
- +' LineNo: '+num+'</li>');
- }
-
- // tail
- return '</ul>';
- },
- xml : function() {
- send('<feed xmlns="http://www.w3.org/2005/Atom">'
- +'<title>Test XML Feed</title>');
-
- while (row = getRow()) {
- var entry = new XML('<entry/>');
- entry.id = row.id;
- entry.title = row.key;
- entry.content = row.value;
- send(entry);
- }
- return "</feed>";
+ provides("html", function() {
+ send("HTML <ul>");
+
+ var row, num = 0;
+ while (row = getRow()) {
+ num ++;
+ send('\n<li>Key: '
+ +row.key+' Value: '+row.value
+ +' LineNo: '+num+'</li>');
}
+
+ // tail
+ return '</ul>';
+ });
+
+ provides("xml", function() {
+ send('<feed xmlns="http://www.w3.org/2005/Atom">'
+ +'<title>Test XML Feed</title>');
+
+ while (row = getRow()) {
+ var entry = new XML('<entry/>');
+ entry.id = row.id;
+ entry.title = row.key;
+ entry.content = row.value;
+ send(entry);
+ }
+ return "</feed>";
});
}),
qsParams: stringFun(function(head, req) {
@@ -127,17 +126,15 @@ couchTests.list_views = function(debug) {
return " tail";
}),
stopIter2: stringFun(function(head, req) {
- respondWith(req, {
- html: function() {
- send("head");
- var row, row_number = 0;
- while(row = getRow()) {
- if(row_number > 2) break;
- send(" " + row_number);
- row_number += 1;
- };
- return " tail";
- }
+ provides("html", function() {
+ send("head");
+ var row, row_number = 0;
+ while(row = getRow()) {
+ if(row_number > 2) break;
+ send(" " + row_number);
+ row_number += 1;
+ };
+ return " tail";
});
}),
tooManyGetRows : stringFun(function() {
diff --git a/share/www/script/test/show_documents.js b/share/www/script/test/show_documents.js
index c87cfb0b..7181a926 100644
--- a/share/www/script/test/show_documents.js
+++ b/share/www/script/test/show_documents.js
@@ -101,28 +101,24 @@ couchTests.show_documents = function(debug) {
};
}
}),
- "respondWith" : stringFun(function(doc, req) {
+ "provides" : stringFun(function(doc, req) {
registerType("foo", "application/foo","application/x-foo");
- return respondWith(req, {
- html : function() {
- return "Ha ha, you said \"" + doc.word + "\".";
- },
- xml : function() {
- var xml = new XML('<xml><node/></xml>');
- // Becase Safari can't stand to see that dastardly
- // E4X outside of a string. Outside of tests you
- // can just use E4X literals.
- eval('xml.node.@foo = doc.word');
- return {
- body: xml
- };
- },
- foo : function() {
- return {
- body: "foofoo"
- };
- },
- fallback : "html"
+
+ provides("html", function() {
+ return "Ha ha, you said \"" + doc.word + "\".";
+ });
+
+ provides("xml", function() {
+ var xml = new XML('<xml><node/></xml>');
+ // Becase Safari can't stand to see that dastardly
+ // E4X outside of a string. Outside of tests you
+ // can just use E4X literals.
+ eval('xml.node.@foo = doc.word');
+ return xml;
+ });
+
+ provides("foo", function() {
+ return "foofoo";
});
})
}
@@ -289,8 +285,8 @@ couchTests.show_documents = function(debug) {
etag = xhr.getResponseHeader("etag");
T(etag != "skipped")
- // test the respondWith mime matcher
- xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/respondWith/"+docid, {
+ // test the provides mime matcher
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/provides/"+docid, {
headers: {
"Accept": 'text/html,application/atom+xml; q=0.9'
}
@@ -301,7 +297,7 @@ couchTests.show_documents = function(debug) {
T(xhr.responseText == "Ha ha, you said \"plankton\".");
// now with xml
- xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/respondWith/"+docid, {
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/provides/"+docid, {
headers: {
"Accept": 'application/xml'
}
@@ -311,7 +307,7 @@ couchTests.show_documents = function(debug) {
T(xhr.responseText.match(/plankton/));
// registering types works
- xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/respondWith/"+docid, {
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/provides/"+docid, {
headers: {
"Accept": "application/x-foo"
}
@@ -319,8 +315,8 @@ couchTests.show_documents = function(debug) {
T(xhr.getResponseHeader("Content-Type") == "application/x-foo");
T(xhr.responseText.match(/foofoo/));
- // test the respondWith mime matcher without
- xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/respondWith/"+docid, {
+ // test the provides mime matcher without a match
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/provides/"+docid, {
headers: {
"Accept": 'text/html,application/atom+xml; q=0.9'
}
@@ -330,6 +326,15 @@ couchTests.show_documents = function(debug) {
T(/text\/html/.test(ct))
T(xhr.responseText == "Ha ha, you said \"plankton\".");
+ // should fallback on the first one
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/provides/"+docid, {
+ headers: {
+ "Accept": 'application/x-foo, application/xml'
+ }
+ });
+ var ct = xhr.getResponseHeader("Content-Type");
+ T(/application\/xml/.test(ct));
+
// test inclusion of conflict state
var doc1 = {_id:"foo", a:1};
var doc2 = {_id:"foo", a:2};