-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($resource): Delete $cancelRequest from toJSON() #15244
Conversation
Thx for the PR. This was an intentional omission though. Since I am going to close this, but if you have a special usecase that breaks because of |
In my opinion, from the method name In many cases, people need the literal object from server without extra keys. I think one should not have to do Thank you. |
That said, I guess it doesn't hurt to remove one more property ourselves (instead of relying on Reopening, but we need some tests for this (if we are making the change, we should make sure there will be no regressions in the future). |
Hm...I just realized Thx @hereblur bringing it up. |
Add test of pull request angular#15244 (angular#15244)
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
1 similar comment
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
1 similar comment
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
CLAs look good, thanks! |
1 similar comment
CLAs look good, thanks! |
result.toJSON() still include $cancelRequest to the JSON output. just simply delete it.
Add test of pull request angular#15244 (angular#15244)
@gkalpak Cool!, Thank you. |
@@ -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(); |
There was a problem hiding this comment.
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
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
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.)
Improved test, per @gkalpak comment, add an expectation that is was there before.
@@ -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(); |
There was a problem hiding this comment.
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.)
create separated test since the existing test always pass without this PR.
@@ -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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this change.
@@ -29,6 +29,9 @@ describe('basic usage', function() { | |||
} | |||
} | |||
|
|||
}, | |||
{ | |||
cancellable: true |
There was a problem hiding this comment.
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.
create separated cancellable resource for test.
|
||
expect(creditCard.$cancelRequest).toBeDefined(); | ||
|
||
$httpBackend.flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
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
).
There was a problem hiding this comment.
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.
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix
What is the current behavior? (You can also link to an open issue here)
result of ngResource.toJSON still include $cancelRequest
What is the new behavior (if this is a feature change)?
remove delete $cancelRequest from ngResource.toJSON's result.
Does this PR introduce a breaking change?
No
Please check if the PR fulfills these requirements
Other information: