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

Commit

Permalink
fix(ngResource): canceling XHR request using promise - refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
netman92 committed Aug 24, 2015
1 parent 2955bbf commit 3da5b53
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,17 @@ angular.module('ngResource', ['ng']).
undefined;

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

Expand Down
8 changes: 3 additions & 5 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ describe('resource', function() {
);
});

it('If timeout promise is resolved, cancel the request', function() {
it('should cancel the request if timeout promise is resolved', function() {
var canceler = $q.defer();

$httpBackend.when('GET', '/CreditCard').respond({data: '123'});
Expand All @@ -1372,7 +1372,7 @@ describe('resource', function() {
CreditCard.query();

canceler.resolve();
expect(function() { $httpBackend.flush();}).toThrow(new Error("No pending request to flush !"));
expect($httpBackend.flush).toThrow(new Error("No pending request to flush !"));

canceler = $q.defer();
CreditCard = $resource('/CreditCard', {}, {
Expand All @@ -1383,9 +1383,7 @@ describe('resource', function() {
});

CreditCard.query();
expect(function() { $httpBackend.flush();}).not.toThrow(new Error("No pending request to flush !"));


expect($httpBackend.flush).not.toThrow();
});


Expand Down

0 comments on commit 3da5b53

Please sign in to comment.