Skip to content

Commit

Permalink
revert: fix($resource): allow XHR request to be cancelled via timeout…
Browse files Browse the repository at this point in the history
… promise

This reverts commit 7170f9d.

Fixes part of angular#13393.
  • Loading branch information
gkalpak committed Dec 7, 2015
1 parent 2995b54 commit 77d4a32
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 42 deletions.
13 changes: 2 additions & 11 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,17 +568,8 @@ angular.module('ngResource', ['ng']).
undefined;

forEach(action, function(value, key) {
switch (key) {
default:
httpConfig[key] = copy(value);
break;
case 'params':
case 'isArray':
case 'interceptor':
break;
case 'timeout':
httpConfig[key] = value;
break;
if (key != 'params' && key != 'isArray' && key != 'interceptor') {
httpConfig[key] = copy(value);
}
});

Expand Down
32 changes: 1 addition & 31 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ describe("resource", function() {
});

describe('resource', function() {
var $httpBackend, $resource, $q;
var $httpBackend, $resource;

beforeEach(module(function($exceptionHandlerProvider) {
$exceptionHandlerProvider.mode('log');
Expand All @@ -1319,7 +1319,6 @@ describe('resource', function() {
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
$resource = $injector.get('$resource');
$q = $injector.get('$q');
}));


Expand Down Expand Up @@ -1357,34 +1356,5 @@ 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();
});


});

0 comments on commit 77d4a32

Please sign in to comment.