From 2ac00f5e253f15afe1ddb08d1ec29af60389b1f6 Mon Sep 17 00:00:00 2001 From: Stanislav Komanec Date: Sun, 23 Aug 2015 20:06:17 +0200 Subject: [PATCH] fix(ngResource): canceling XHR request using promise - refactor --- src/ngResource/resource.js | 15 +++++++++++---- test/ngResource/resourceSpec.js | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index 46642157db20..07a11c49fcdc 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -568,10 +568,17 @@ angular.module('ngResource', ['ng']). undefined; forEach(action, function(value, key) { - if (key != 'params' && key != 'isArray' && key != 'interceptor' && key != 'timeout') { - httpConfig[key] = copy(value); - } else if (key == 'timeout') { - httpConfig[key] = value; + switch (key) { + default: + httpConfig[key] = copy(value); + break; + case 'params': + case 'isArray': + case 'interceptor': + break; + case 'timeout': + httpConfig[key] = value; + break; } }); diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index b19bb53ddd0f..a8edc58eedd7 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -1357,7 +1357,7 @@ describe('resource', function() { ); }); - it('If timeout promise is resolved, cancel the request', function() { + it('should cancel the request if timeout promise is resolved', function() { var canceler = $q.defer(); $httpBackend.when('GET', '/CreditCard').respond({data: '123'});