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 2 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
3 changes: 2 additions & 1 deletion test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,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 and $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();
Expand All @@ -750,6 +750,7 @@ describe('basic usage', function() {
var json = JSON.parse(angular.toJson(cc));
expect(json.$promise).not.toBeDefined();
expect(json.$resolved).not.toBeDefined();
expect(json.$cancelRequest).not.toBeDefined();
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add an expectation that is was there before? (Similar to what we have for $promise/$resolved.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Member

Choose a reason for hiding this comment

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

I just realized that this test uses JSON.parse(angular.toJson(cc)), which means it would pass even without this PR.
Can you add a new test (similar to this one) that uses cc.toJSON() directly? (Leave this one as is - it doesn't hurt.)

expect(json).toEqual({id: 123, number: '9876', $myProp: 'still here'});
});

Expand Down