Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var stripSlashes = function (name) {
module.exports = {
init: function () {
_.extend(this, {
methods: ['find', 'get', 'create', 'update', 'remove'],
methods: ['find', 'get', 'create', 'update', 'patch', 'remove'],
mixins: mixins,
services: {},
providers: []
Expand Down
12 changes: 7 additions & 5 deletions 12 lib/providers/rest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ module.exports = function (config) {

// GET / -> service.find(cb, params)
app.get(uri, app.rest.find(service))
// GET /:id -> service.get(cb, id, params)
// GET /:id -> service.get(id, params, cb)
.get(uri + '/:id', app.rest.get(service))
// POST -> service.create(cb, data, params)
// POST -> service.create(data, params, cb)
.post(uri, app.rest.create(service))
// PUT /:id -> service.update(cb, id, data, params)
// PUT /:id -> service.update(id, data, params, cb)
.put(uri + '/:id', app.rest.update(service))
// DELETE /:id -> service.remove(cb, id, params)
.del(uri + '/:id', app.rest.remove(service));
// DELETE /:id -> service.remove(id, params, cb)
.del(uri + '/:id', app.rest.remove(service))
// PATCH /:id -> service.patch(id, data, params, callback)
.patch(uri + '/:id', app.rest.patch(service));

app.use(uri, responder);
});
Expand Down
11 changes: 11 additions & 0 deletions 11 lib/providers/rest/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ module.exports = {
};
},

patch: function(service) {
return function(req, res, next) {
var error = checkMethod(res, service, 'patch');
if (error) {
return next(error);
}

service.patch(req.params.id, req.body, getParams(req), wrap(req, res, next));
};
},

remove: function(service) {
return function(req, res, next) {
var error = checkMethod(res, service, 'remove');
Expand Down
12 changes: 12 additions & 0 deletions 12 test/providers/primus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ describe('Primus provider', function () {
});
});

it('::patch', function (done) {
var original = {
name: 'patching'
};

socket.send('todo::patch', 25, original, {}, function (error, data) {
verify.patch(25, original, data);

done(error);
});
});

it('::remove', function (done) {
socket.send('todo::remove', 11, {}, function (error, data) {
verify.remove(11, data);
Expand Down
20 changes: 20 additions & 0 deletions 20 test/providers/rest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ describe('REST provider', function () {
});
});

it('PATCH .patch', function (done) {
var original = {
description: 'PATCH .patch'
};

request({
url: 'http://localhost:4777/todo/544',
method: 'patch',
body: JSON.stringify(original),
headers: {
'Content-Type': 'application/json'
}
}, function (error, response, body) {
assert.ok(response.statusCode === 200, 'Got OK status code');
verify.patch(544, original, JSON.parse(body));

done(error);
});
});

it('DELETE .remove', function (done) {
request({
url: 'http://localhost:4777/todo/233',
Expand Down
15 changes: 15 additions & 0 deletions 15 test/providers/service-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ exports.Service = {
callback(null, result);
},

patch: function (id, data, params, callback) {
var result = _.clone(data);
result.id = id;
result.status = 'patched';
callback(null, result);
},

remove: function (id, params, callback) {
callback(null, {
id: id
Expand Down Expand Up @@ -70,6 +77,14 @@ exports.verify = {
assert.deepEqual(expected, current, 'Data ran through .update as expected');
},

patch: function (id, original, current) {
var expected = _.extend({}, original, {
id: id,
status: 'patched'
});
assert.deepEqual(expected, current, 'Data ran through .patch as expected');
},

remove: function (id, data) {
assert.deepEqual({
id: id
Expand Down
12 changes: 12 additions & 0 deletions 12 test/providers/socketio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ describe('SocketIO provider', function () {
});
});

it('::patch', function (done) {
var original = {
name: 'patching'
};

socket.emit('todo::patch', 25, original, {}, function (error, data) {
verify.patch(25, original, data);

done(error);
});
});

it('::remove', function (done) {
socket.emit('todo::remove', 11, {}, function (error, data) {
verify.remove(11, data);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.