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 4 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
17 changes: 16 additions & 1 deletion test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ describe('basic usage', function() {
}
}

},
{
cancellable: true
Copy link
Member

Choose a reason for hiding this comment

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

Nit: It probably doesn't matter, but I would rather keep changes local, instead of affecting all tests. I.e. create a new, cancellable resource for your test.

});
callback = jasmine.createSpy('callback');
}));
Expand Down Expand Up @@ -737,7 +740,7 @@ describe('basic usage', function() {
expect(person2).toEqual(jasmine.any(Person));
});

it('should not include $promise and $resolved when resource is toJson\'ed', function() {
it('should not include $promise, $resolved when resource is toJson\'ed', function() {
Copy link
Member

Choose a reason for hiding this comment

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

Revert this change.

$httpBackend.expect('GET', '/CreditCard/123').respond({id: 123, number: '9876'});
var cc = CreditCard.get({id: 123});
$httpBackend.flush();
Expand All @@ -753,6 +756,18 @@ 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.expect('GET', '/CreditCard/123').respond({id: 123, number: '9876'});
var cc = CreditCard.get({id: 123});
$httpBackend.flush();

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

var json = cc.toJSON();

expect(json.$cancelRequest).not.toBeDefined();
});

describe('promise api', function() {

var $rootScope;
Expand Down