diff --git a/sails.io.js b/sails.io.js index 9c7bac2..d97dc11 100644 --- a/sails.io.js +++ b/sails.io.js @@ -1191,6 +1191,31 @@ }; + /** + * Simulate a PATCH request to sails + * e.g. + * `socket.patch('/event/3', changedFields, $spinner.hide)` + * + * @api public + * @param {String} url :: destination URL + * @param {Object} data :: parameters to send with the request [optional] + * @param {Function} cb :: callback function to call when finished [optional] + */ + + SailsSocket.prototype.patch = function(url, data, cb) { + + // `data` is optional + if (typeof data === 'function') { + cb = data; + data = {}; + } + + return this.request({ + method: 'patch', + params: data, + url: url + }, cb); + }; /** * Simulate a DELETE request to sails diff --git a/test/basic.test.js b/test/basic.test.js index 1a0ef6c..98aaec7 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -50,7 +50,8 @@ var EXPECTED_RESPONSES = { }, 'delete /hello': { body: 'deleted!'}, 'post /hello': { body: 'posted!'}, - 'put /hello': { body: 'putted!'} + 'put /hello': { body: 'putted!'}, + 'patch /hello': { body: 'patched!'} }; var setupRoutes = _setupRoutes(EXPECTED_RESPONSES); @@ -101,6 +102,13 @@ describe('io.socket', function () { }); }); + it('should be able to send a PATCH request and receive the expected response', function (cb) { + io.socket.patch('/hello', function (body, jwr) { + assertResponse('patch /hello', arguments); + return cb(); + }); + }); + it('should receive JSON as a POJO, not a string', function (cb) { io.socket.get('/someJSON', function (body, jwr) { assertResponse('get /someJSON', arguments);