fix($http): remove support for PATCH + better whenXXX, expectXXX api

- there are too many unknowns about PATCH, so I'm dropping its support until we know that this is actually useful
- expectGET, expectHEAD and expectJSON (and the same for whenXXX) should not require response data to be specified
This commit is contained in:
Igor Minar 2012-01-10 10:17:05 -08:00
parent e7a23e4b65
commit 46691c2721
4 changed files with 12 additions and 18 deletions

12
src/angular-mocks.js vendored
View file

@ -748,11 +748,17 @@ function createHttpBackendMock($delegate, $defer) {
function createShortMethods(prefix) {
angular.forEach(['GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'JSONP'], function(method) {
$httpBackend[prefix + method] = function(url, data, headers) {
return $httpBackend[prefix](method, url, data, headers)
angular.forEach(['GET', 'DELETE', 'JSONP'], function(method) {
$httpBackend[prefix + method] = function(url, headers) {
return $httpBackend[prefix](method, url, undefined, headers)
}
});
angular.forEach(['PUT', 'POST'], function(method) {
$httpBackend[prefix + method] = function(url, data, headers) {
return $httpBackend[prefix](method, url, data, headers)
}
});
}
};

View file

@ -287,7 +287,7 @@ function $HttpProvider() {
* @param {Object=} config Optional configuration object
* @returns {XhrFuture} Future object
*/
createShortMethods('get', 'delete', 'head', 'patch', 'jsonp');
createShortMethods('get', 'delete', 'head', 'jsonp');
/**
* @ngdoc method

View file

@ -819,9 +819,9 @@ describe('ngMock', function() {
});
describe('expect/when shorcuts', function() {
describe('expect/when shortcuts', function() {
angular.forEach(['expect', 'when'], function(prefix) {
angular.forEach(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'JSONP'], function(method) {
angular.forEach(['GET', 'POST', 'PUT', 'DELETE', 'JSONP'], function(method) {
var shortcut = prefix + method;
it('should provide ' + shortcut + ' shortcut method', function() {
hb[shortcut]('/foo').respond('bar');

View file

@ -479,18 +479,6 @@ describe('$http', function() {
});
it('should have patch()', function() {
$httpBackend.expect('PATCH', '/url').respond('');
$http.patch('/url');
});
it('patch() should allow config param', function() {
$httpBackend.expect('PATCH', '/url', undefined, checkHeader('Custom', 'Header')).respond('');
$http.patch('/url', {headers: {'Custom': 'Header'}});
});
it('should have post()', function() {
$httpBackend.expect('POST', '/url', 'some-data').respond('');
$http.post('/url', 'some-data');