This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +40
-12
lines changed
2 files changed +40
-12
lines changed Original file line number Diff line number Diff line change @@ -576,18 +576,17 @@ angular.module('ngResource', ['ng']).
576
576
577
577
forEach ( actions , function ( action , name ) {
578
578
var hasBody = / ^ ( P O S T | P U T | P A T C H ) $ / i. test ( action . method ) ;
579
- var cancellable ;
580
-
581
- if ( angular . isNumber ( action . timeout ) ) {
582
- cancellable = false ;
583
- } else if ( action . timeout ) {
584
- $log . debug ( 'ngResource:\n' +
585
- ' Only numeric values are allowed as `timeout`.\n' +
586
- ' Promises are not supported in $resource, because the same value has to ' +
587
- 'be re-used for multiple requests. If you are looking for a way to cancel ' +
588
- 'requests, you should use the `cancellable` option.' ) ;
589
- delete action . timeout ;
590
- } else {
579
+ var cancellable = false ;
580
+
581
+ if ( ! angular . isNumber ( action . timeout ) ) {
582
+ if ( action . timeout ) {
583
+ $log . debug ( 'ngResource:\n' +
584
+ ' Only numeric values are allowed as `timeout`.\n' +
585
+ ' Promises are not supported in $resource, because the same value has to ' +
586
+ 'be re-used for multiple requests. If you are looking for a way to cancel ' +
587
+ 'requests, you should use the `cancellable` option.' ) ;
588
+ delete action . timeout ;
589
+ }
591
590
cancellable = angular . isDefined ( action . cancellable ) ? action . cancellable :
592
591
( options && angular . isDefined ( options . cancellable ) ) ? options . cancellable :
593
592
provider . defaults . cancellable ;
Original file line number Diff line number Diff line change @@ -1427,6 +1427,35 @@ describe('cancelling requests', function() {
1427
1427
} )
1428
1428
) ;
1429
1429
1430
+ it ( 'should use `cancellable` value if passed a non-numeric `timeout` in an action' ,
1431
+ inject ( function ( $log , $q ) {
1432
+ spyOn ( $log , 'debug' ) ;
1433
+ $httpBackend . whenGET ( '/CreditCard' ) . respond ( { } ) ;
1434
+
1435
+ var CreditCard = $resource ( '/CreditCard' , { } , {
1436
+ get : {
1437
+ method : 'GET' ,
1438
+ timeout : $q . defer ( ) . promise ,
1439
+ cancellable : true
1440
+ }
1441
+ } ) ;
1442
+
1443
+ var creditCard = CreditCard . get ( ) ;
1444
+ expect ( creditCard . $cancelRequest ) . toBeDefined ( ) ;
1445
+ expect ( httpSpy . calls [ 0 ] . args [ 0 ] . timeout . then ) . toBeDefined ( ) ;
1446
+
1447
+ // $httpBackend.flush();
1448
+
1449
+ // expect(httpSpy).toHaveBeenCalledOnce();
1450
+ // expect(httpSpy.calls[0].args[0].timeout).toBe(jasmine.any());
1451
+ // expect($log.debug).toHaveBeenCalledOnceWith('ngResource:\n' +
1452
+ // ' Only numeric values are allowed as `timeout`.\n' +
1453
+ // ' Promises are not supported in $resource, because the same value has to ' +
1454
+ // 'be re-used for multiple requests. If you are looking for a way to cancel ' +
1455
+ // 'requests, you should use the `cancellable` option.');
1456
+ } )
1457
+ ) ;
1458
+
1430
1459
it ( 'should not create a `$cancelRequest` method for instance calls' , function ( ) {
1431
1460
$httpBackend . whenPOST ( '/CreditCard' ) . respond ( { } ) ;
1432
1461
You can’t perform that action at this time.
0 commit comments