diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index 19bc84dd9233..514e4c81b72b 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -368,7 +368,7 @@ angular.module('ngResource', ['ng']). } }; - this.$get = ['$http', '$q', function($http, $q) { + this.$get = ['$http', '$log', '$q', function($http, $log, $q) { var noop = angular.noop, forEach = angular.forEach, @@ -579,6 +579,16 @@ angular.module('ngResource', ['ng']). case 'isArray': case 'interceptor': break; + case 'timeout': + if (value && !angular.isNumber(value)) { + $log.debug('ngResource:\n' + + ' Only numeric values are allowed as `timeout`.\n' + + ' Promises are not supported in $resource, because the same value would ' + + 'be used for multiple requests.\n' + + ' If you need support for cancellable $resource actions, you should ' + + 'upgrade to version 1.5 or higher.'); + } + break; } }); diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index 79450e4f24ea..560f71ac1f3d 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -1355,6 +1355,48 @@ describe('resource', function() { /^\[\$resource:badcfg\] Error in resource configuration for action `get`\. Expected response to contain an object but got an array \(Request: GET \/Customer\/123\)/ ); }); +}); + +describe('resource with promises as `timeout`', function() { + var httpSpy; + var $httpBackend; + var $resource; + + beforeEach(module('ngResource', function($provide) { + $provide.decorator('$http', function($delegate) { + httpSpy = jasmine.createSpy('$http').andCallFake($delegate); + return httpSpy; + }); + })); + + beforeEach(inject(function(_$httpBackend_, _$resource_) { + $httpBackend = _$httpBackend_; + $resource = _$resource_; + })); + it('should ignore non-numeric timeouts in actions and log a $debug message', + inject(function($log, $q) { + spyOn($log, 'debug'); + $httpBackend.whenGET('/CreditCard').respond({}); + + var CreditCard = $resource('/CreditCard', {}, { + get: { + method: 'GET', + timeout: $q.defer().promise + } + }); + + CreditCard.get(); + $httpBackend.flush(); + expect(httpSpy).toHaveBeenCalledOnce(); + expect(httpSpy.calls[0].args[0].timeout).toBeUndefined(); + expect($log.debug).toHaveBeenCalledOnceWith('ngResource:\n' + + ' Only numeric values are allowed as `timeout`.\n' + + ' Promises are not supported in $resource, because the same value would ' + + 'be used for multiple requests.\n' + + ' If you need support for cancellable $resource actions, you should ' + + 'upgrade to version 1.5 or higher.'); + }) + ); });