Skip to content

Commit

Permalink
fix($resource): don't add noop $cancelRequest after request has resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Nov 26, 2015
1 parent 7ddbc9a commit b183eae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ angular.module('ngResource', ['ng']).

promise.finally(function() {
value.$resolved = true;
if (cancellable) {
if (!isInstanceCall && cancellable) {
value.$cancelRequest = angular.noop;
timeoutDeferred = httpConfig.timeout = null;
}
Expand Down
9 changes: 8 additions & 1 deletion test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,8 @@ describe('cancelling requests', function() {
);

it('should not create a `$cancelRequest` method for instance calls', function() {
$httpBackend.whenPOST('/CreditCard').respond({});

var CreditCard = $resource('/CreditCard', {}, {
save1: {
method: 'POST',
Expand All @@ -1448,6 +1450,11 @@ describe('cancelling requests', function() {
var promise2 = creditCard.$save2();
expect(promise2.$cancelRequest).toBeUndefined();
expect(creditCard.$cancelRequest).toBeUndefined();

$httpBackend.flush();
expect(promise1.$cancelRequest).toBeUndefined();
expect(promise2.$cancelRequest).toBeUndefined();
expect(creditCard.$cancelRequest).toBeUndefined();
});

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

describe('resource wrt configuring `cancellable` on the provider', function() {
describe('configuring `cancellable` on the provider', function() {
var $resource;

beforeEach(module('ngResource', function($resourceProvider) {
Expand Down

0 comments on commit b183eae

Please sign in to comment.