Permalink
Browse files

Added PATCH support with tests. Also fixes root resources tests. #70

  • Loading branch information...
1 parent 5d2f6d6 commit 0b6eb3fc63427244bcc366fb758fa02c4a36a281 @andy-shea andy-shea committed Apr 1, 2013
Showing with 89 additions and 21 deletions.
  1. +11 −7 index.js
  2. +4 −0 test/fixtures/forum.js
  3. +4 −0 test/fixtures/thread.js
  4. +70 −14 test/resource.test.js
View
@@ -22,13 +22,14 @@ var express = require('express')
*/
var orderedActions = [
- 'index' // GET /
- , 'new' // GET /new
- , 'create' // POST /
- , 'show' // GET /:id
- , 'edit' // GET /edit/:id
- , 'update' // PUT /:id
- , 'destroy' // DEL /:id
+ 'index' // GET /
+ , 'new' // GET /new
+ , 'create' // POST /
+ , 'show' // GET /:id
+ , 'edit' // GET /edit/:id
+ , 'update' // PUT /:id
+ , 'patch' // PATCH /:id
+ , 'destroy' // DEL /:id
];
/**
@@ -233,6 +234,9 @@ Resource.prototype.mapDefaultAction = function(key, fn){
case 'update':
this.put(fn);
break;
+ case 'patch':
+ this.patch(fn);
+ break;
case 'destroy':
this.del(fn);
break;
@@ -23,6 +23,10 @@ exports.update = function(req, res){
res.send('update forum ' + req.params.forum);
};
+exports.patch = function(req, res){
+ res.send('patch forum ' + req.params.forum);
+};
+
exports.destroy = function(req, res){
res.send('destroy forum ' + req.params.forum);
};
@@ -23,6 +23,10 @@ exports.update = function(req, res){
res.send('update thread ' + req.params.thread + ' of forum ' + req.params.forum);
};
+exports.patch = function(req, res){
+ res.send('patch thread ' + req.params.thread + ' of forum ' + req.params.forum);
+};
+
exports.destroy = function(req, res){
res.send('destroy thread ' + req.params.thread + ' of forum ' + req.params.forum);
};
View
@@ -41,6 +41,14 @@ describe('app.resource()', function(){
request(app)
.get('/forums/5/edit')
.expect('edit forum 5', next());
+
+ request(app)
+ .put('/forums/5')
+ .expect('update forum 5', next());
+
+ request(app)
+ .patch('/forums/5')
+ .expect('patch forum 5', next());
request(app)
.del('/forums/5')
@@ -50,25 +58,73 @@ describe('app.resource()', function(){
it('should support root resources', function(done){
var app = express();
var next = batch(done);
- var forum = app.resource(require('./fixtures/forum'));
+ var forum = app.resource('forums', require('./fixtures/forum'));
var thread = app.resource('threads', require('./fixtures/thread'));
forum.map(thread);
request(app)
- .get('/')
+ .get('/forums')
.expect('forum index', next());
+
+ request(app)
+ .get('/forums/new')
+ .expect('new forum', next());
+
+ request(app)
+ .post('/forums')
+ .expect('create forum', next());
+
+ request(app)
+ .get('/forums/12')
+ .expect('show forum 12', next());
+
+ request(app)
+ .get('/forums/12/edit')
+ .expect('edit forum 12', next());
+
+ request(app)
+ .put('/forums/12')
+ .expect('update forum 12', next());
+
+ request(app)
+ .patch('/forums/12')
+ .expect('patch forum 12', next());
+
+ request(app)
+ .del('/forums/12')
+ .expect('destroy forum 12', next());
- // request(app)
- // .get('/12')
- // .expect('show forum 12', next());
-
- // request(app)
- // .get('/12/threads')
- // .expect('thread index of forum 12', next());
-
- // request(app)
- // .get('/1/threads/50')
- // .expect('show thread 50 of forum 1', next());
+ request(app)
+ .get('/forums/12/threads')
+ .expect('thread index of forum 12', next());
+
+ request(app)
+ .get('/forums/12/threads/new')
+ .expect('new thread', next());
+
+ request(app)
+ .post('/forums/12/threads')
+ .expect('create thread', next());
+
+ request(app)
+ .get('/forums/12/threads/50')
+ .expect('show thread 50 of forum 12', next());
+
+ request(app)
+ .get('/forums/12/threads/50/edit')
+ .expect('edit thread 50 of forum 12', next());
+
+ request(app)
+ .put('/forums/12/threads/50')
+ .expect('update thread 50 of forum 12', next());
+
+ request(app)
+ .patch('/forums/12/threads/50')
+ .expect('patch thread 50 of forum 12', next());
+
+ request(app)
+ .del('/forums/12/threads/50')
+ .expect('destroy thread 50 of forum 12', next())
})
describe('"id" option', function(){
@@ -193,4 +249,4 @@ describe('app.resource()', function(){
})
})
})
-})
+})

0 comments on commit 0b6eb3f

Please sign in to comment.