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

fix($resource): Delete $cancelRequest from toJSON() #15244

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ angular.module('ngResource', ['ng']).
var data = extend({}, this);
delete data.$promise;
delete data.$resolved;
delete data.$cancelRequest;
return data;
};

Expand Down
20 changes: 20 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,26 @@ describe('basic usage', function() {
expect(json).toEqual({id: 123, number: '9876', $myProp: 'still here'});
});

it('should not include $cancelRequest when resource is toJson\'ed', function() {
$httpBackend.whenGET('/CreditCard').respond({});

var CreditCard = $resource('/CreditCard', {}, {
get: {
method: 'GET',
cancellable: true
}
});

var creditCard = CreditCard.get();

expect(creditCard.$cancelRequest).toBeDefined();

$httpBackend.flush();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to make sure It was there before remove it. same as the test next to it (for $promise and $resolved).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be there even before flush $http, isn't it?
If $httpBackend doesn't complain, just remove the flushing.


var json = creditCard.toJSON();
expect(json.$cancelRequest).not.toBeDefined();
});

describe('promise api', function() {

var $rootScope;
Expand Down