Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit b183eae

Browse files
fix($resource): don't add noop $cancelRequest after request has resolved
1 parent 7ddbc9a commit b183eae

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/ngResource/resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ angular.module('ngResource', ['ng']).
706706

707707
promise.finally(function() {
708708
value.$resolved = true;
709-
if (cancellable) {
709+
if (!isInstanceCall && cancellable) {
710710
value.$cancelRequest = angular.noop;
711711
timeoutDeferred = httpConfig.timeout = null;
712712
}

test/ngResource/resourceSpec.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,8 @@ describe('cancelling requests', function() {
14281428
);
14291429

14301430
it('should not create a `$cancelRequest` method for instance calls', function() {
1431+
$httpBackend.whenPOST('/CreditCard').respond({});
1432+
14311433
var CreditCard = $resource('/CreditCard', {}, {
14321434
save1: {
14331435
method: 'POST',
@@ -1448,6 +1450,11 @@ describe('cancelling requests', function() {
14481450
var promise2 = creditCard.$save2();
14491451
expect(promise2.$cancelRequest).toBeUndefined();
14501452
expect(creditCard.$cancelRequest).toBeUndefined();
1453+
1454+
$httpBackend.flush();
1455+
expect(promise1.$cancelRequest).toBeUndefined();
1456+
expect(promise2.$cancelRequest).toBeUndefined();
1457+
expect(creditCard.$cancelRequest).toBeUndefined();
14511458
});
14521459

14531460
it('should not create a `$cancelRequest` method for non-cancellable calls', function() {
@@ -1546,7 +1553,7 @@ describe('cancelling requests', function() {
15461553
});
15471554
});
15481555

1549-
describe('resource wrt configuring `cancellable` on the provider', function() {
1556+
describe('configuring `cancellable` on the provider', function() {
15501557
var $resource;
15511558

15521559
beforeEach(module('ngResource', function($resourceProvider) {

0 commit comments

Comments
 (0)