Skip to content
Browse files

fix tests

  • Loading branch information...
1 parent 1e0d114 commit f63131219b71b94a9a4e6fb41b8b159cb9869936 @klaemo klaemo committed Aug 3, 2012
Showing with 21 additions and 3 deletions.
  1. +6 −1 tests/fixtures/show/query.json
  2. +15 −2 tests/show/query.js
View
7 tests/fixtures/show/query.json
@@ -6,7 +6,7 @@
}
, { "method" : "put"
, "path" : "/show_query/_design/people"
- , "body" : "{\"shows\":{\"singleDoc\":\"function (doc, req) { return { body: { name: doc.name, city: doc.city, format: 'json' }, headers: { 'Content-Type': 'application/json' } }; }\"}}"
+ , "body" : "{\"shows\":{\"singleDoc\":\"function (doc, req) {\\n if(req.query.format === 'json' || !req.query.format) {\\n return { body: JSON.stringify({ name: doc.name, city: doc.city, format: 'json' }), headers: { 'Content-Type': 'application/json' } };\\n }\\n if(req.query.format === 'html') {\\n return { body: 'Hello Clemens!', headers: { 'Content-Type': 'text/html' } };\\n }\\n }\"}}"
, "status" : 201
, "response" : "{\"ok\":true,\"id\":\"_design/people\",\"rev\":\"1-14e6bc\"}"
}
@@ -30,6 +30,11 @@
}
, { "path" : "/show_query/_design/people/_show/singleDoc/p_clemens"
, "response" : "{\"name\":\"Clemens\",\"city\":\"Dresden\",\"format\":\"json\"}\n"
+ , "headers" : { "content-type": "application/json" }
+ }
+, { "path" : "/show_query/_design/people/_show/singleDoc/p_clemens?format=html"
+ , "response" : "Hello Clemens!"
+ , "headers" : { "content-type": "text/html" }
}
, { "method" : "delete"
, "path" : "/show_query"
View
17 tests/show/query.js
@@ -15,7 +15,14 @@ specify("show_query:setup", timeout, function (assert) {
assert.equal(err, undefined, "Failed to create database");
db.insert(
{ "shows": {
- "singleDoc": function(doc, req) { return { body: { name: doc.name, city: doc.city, format: 'json' }, headers: { 'Content-Type': 'application/json' } }; }
+ "singleDoc": function(doc, req) {
+ if(req.query.format === 'json' || !req.query.format) {
+ return { body: JSON.stringify({ name: doc.name, city: doc.city, format: 'json' }), headers: { 'Content-Type': 'application/json' } };
+ }
+ if(req.query.format === 'html') {
+ return { body: 'Hello Clemens!', headers: { 'Content-Type': 'text/html' } };
+ }
+ }
}
}, '_design/people', function (error, response) {
assert.equal(error, undefined, "Failed to create show function");
@@ -36,12 +43,18 @@ specify("show_query:setup", timeout, function (assert) {
});
specify("show_query:test", timeout, function (assert) {
- db.show('people','singleDoc', 'p_clemens', function (error, doc) {
+ db.show('people','singleDoc', 'p_clemens', function (error, doc, rh) {
assert.equal(error, undefined, "Show function didn't respond");
+ assert.equal(rh['content-type'], 'application/json');
assert.equal(doc.name,'Clemens');
assert.equal(doc.city,'Dresden');
assert.equal(doc.format,'json');
});
+ db.show('people','singleDoc', 'p_clemens', { format: 'html' }, function (error, doc, rh) {
+ assert.equal(error, undefined, "Show function didn't respond");
+ assert.equal(rh['content-type'], 'text/html');
+ assert.equal(doc,'Hello Clemens!');
+ });
});
specify("show_query:teardown", timeout, function (assert) {

0 comments on commit f631312

Please sign in to comment.
Something went wrong with that request. Please try again.