diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index 34ba768716b9..565b104ba074 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -568,8 +568,17 @@ angular.module('ngResource', ['ng']). undefined; forEach(action, function(value, key) { - if (key != 'params' && key != 'isArray' && key != 'interceptor') { - httpConfig[key] = copy(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 79450e4f24ea..2ac1454bd48b 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -1308,7 +1308,7 @@ describe("resource", function() { }); describe('resource', function() { - var $httpBackend, $resource; + var $httpBackend, $resource, $q; beforeEach(module(function($exceptionHandlerProvider) { $exceptionHandlerProvider.mode('log'); @@ -1319,6 +1319,7 @@ describe('resource', function() { beforeEach(inject(function($injector) { $httpBackend = $injector.get('$httpBackend'); $resource = $injector.get('$resource'); + $q = $injector.get('$q'); })); @@ -1356,5 +1357,34 @@ describe('resource', function() { ); }); + it('should cancel the request if timeout promise is resolved', function() { + var canceler = $q.defer(); + + $httpBackend.when('GET', '/CreditCard').respond({data: '123'}); + + var CreditCard = $resource('/CreditCard', {}, { + query: { + method: 'GET', + timeout: canceler.promise + } + }); + + CreditCard.query(); + + canceler.resolve(); + expect($httpBackend.flush).toThrow(new Error("No pending request to flush !")); + + canceler = $q.defer(); + CreditCard = $resource('/CreditCard', {}, { + query: { + method: 'GET', + timeout: canceler.promise + } + }); + + CreditCard.query(); + expect($httpBackend.flush).not.toThrow(); + }); + });