Skip to content

Commit

Permalink
[fix test] Fix a case where only some routes have accept
Browse files Browse the repository at this point in the history
Add a test case for that case.
  • Loading branch information
mmalecki committed Jul 20, 2012
1 parent cdcd586 commit c583a86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/director/http/index.js
Expand Up @@ -120,7 +120,7 @@ Router.prototype.dispatch = function (req, res, callback) {
if (this._hasAccepts) {
contentType = req.headers['content-type'];
fns = this.traverse(method, url, this.routes, '', function (route) {
return route.accept.some(function (a) {
return !route.accept || route.accept.some(function (a) {
return a.test(contentType);
});
});
Expand Down
14 changes: 14 additions & 0 deletions test/server/http/accept-test.js
Expand Up @@ -25,6 +25,14 @@ apiEasy.describe('director/http/accept')
router.get('/txt', { accept: 'text/plain' }, handlers.respondWithOk());
router.get('/both', { accept: ['text/plain', 'application/json'] }, handlers.respondWithOk());
router.get('/regex', { accept: /.+\/x\-.+/ }, handlers.respondWithOk());

router.get('/weird', { accept: 'application/json' }, function () {
this.res.writeHead(400);
this.res.end();
});

router.get('/weird', handlers.respondWithOk());

helpers.createServer(router).listen(PORT, this.callback);
},
"should be created": function (err) {
Expand All @@ -44,6 +52,8 @@ apiEasy.describe('director/http/accept')
.expect(200)
.get('/regex')
.expect(404)
.get('/weird')
.expect(400)
.undiscuss()
.next()
.discuss('with `content-type: text/plain`')
Expand All @@ -56,6 +66,8 @@ apiEasy.describe('director/http/accept')
.expect(200)
.get('/regex')
.expect(404)
.get('/weird')
.expect(200)
.undiscuss()
.next()
.discuss('with `content-type: application/x-tar-gz`')
Expand All @@ -69,6 +81,8 @@ apiEasy.describe('director/http/accept')
.expect(404)
.get('/regex')
.expect(200)
.get('/weird')
.expect(200)
.undiscuss()
.export(module);

0 comments on commit c583a86

Please sign in to comment.