diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 0b8f016ff9d5..a2d4f88be9f1 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -1111,6 +1111,20 @@ function createHttpBackendMock($delegate, $browser) { * request is handled. */ + /** + * @ngdoc method + * @name angular.module.ngMock.$httpBackend#expectPATCH + * @methodOf angular.module.ngMock.$httpBackend + * @description + * Creates a new request expectation for PATCH requests. For more info see `expect()`. + * + * @param {string|RegExp} url HTTP url. + * @param {(string|RegExp)=} data HTTP request body. + * @param {Object=} headers HTTP headers. + * @returns {requestHandler} Returns an object with `respond` method that control how a matched + * request is handled. + */ + /** * @ngdoc method * @name angular.module.ngMock.$httpBackend#expectJSONP @@ -1220,7 +1234,7 @@ function createHttpBackendMock($delegate, $browser) { } }); - angular.forEach(['PUT', 'POST'], function(method) { + angular.forEach(['PUT', 'POST', 'PATCH'], function(method) { $httpBackend[prefix + method] = function(url, data, headers) { return $httpBackend[prefix](method, url, data, headers) } @@ -1483,6 +1497,20 @@ angular.module('ngMockE2E', ['ng']).config(function($provide) { * control how a matched request is handled. */ +/** + * @ngdoc method + * @name angular.module.ngMockE2E.$httpBackend#whenPATCH + * @methodOf angular.module.ngMockE2E.$httpBackend + * @description + * Creates a new backend definition for PATCH requests. For more info see `when()`. + * + * @param {string|RegExp} url HTTP url. + * @param {(string|RegExp)=} data HTTP request body. + * @param {(Object|function(Object))=} headers HTTP headers. + * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that + * control how a matched request is handled. + */ + /** * @ngdoc method * @name angular.module.ngMockE2E.$httpBackend#whenJSONP diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index db1984010fcc..d19a1d6a6aee 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -318,7 +318,7 @@ angular.module('ngResource', ['ng']). } forEach(actions, function(action, name) { - var isPostOrPut = action.method == 'POST' || action.method == 'PUT'; + var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH'; Resource[name] = function(a1, a2, a3, a4) { var params = {}; var data; @@ -349,7 +349,7 @@ angular.module('ngResource', ['ng']). } case 1: if (isFunction(a1)) success = a1; - else if (isPostOrPut) data = a1; + else if (hasBody) data = a1; else params = a1; break; case 0: break; @@ -409,7 +409,7 @@ angular.module('ngResource', ['ng']). throw "Expected between 1-3 arguments [params, success, error], got " + arguments.length + " arguments."; } - var data = isPostOrPut ? this : undefined; + var data = hasBody ? this : undefined; Resource[name].call(this, params, data, success, error); }; }); diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 4b2666b73b09..22c91a4dd26c 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -814,7 +814,7 @@ describe('ngMock', function() { describe('expect/when shortcuts', function() { angular.forEach(['expect', 'when'], function(prefix) { - angular.forEach(['GET', 'POST', 'PUT', 'DELETE', 'JSONP'], function(method) { + angular.forEach(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'JSONP'], function(method) { var shortcut = prefix + method; it('should provide ' + shortcut + ' shortcut method', function() { hb[shortcut]('/foo').respond('bar');