mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Don't mutate resource if server responded with no body
If the server provides response with no body to a resource request, resource should not mutate the resource model in the callback.
This commit is contained in:
parent
4da65d0e8c
commit
94514a91f8
2 changed files with 23 additions and 7 deletions
|
|
@ -97,13 +97,15 @@ ResourceFactory.prototype = {
|
|||
data,
|
||||
function(status, response, clear) {
|
||||
if (status == 200) {
|
||||
if (action.isArray) {
|
||||
value.length = 0;
|
||||
forEach(response, function(item){
|
||||
value.push(new Resource(item));
|
||||
});
|
||||
} else {
|
||||
copy(response, value);
|
||||
if (response) {
|
||||
if (action.isArray) {
|
||||
value.length = 0;
|
||||
forEach(response, function(item){
|
||||
value.push(new Resource(item));
|
||||
});
|
||||
} else {
|
||||
copy(response, value);
|
||||
}
|
||||
}
|
||||
(callback||noop)(value);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -177,6 +177,20 @@ describe("resource", function() {
|
|||
expect(callback).wasCalledWith(cc);
|
||||
});
|
||||
|
||||
it('should not mutate the resource object if response contains no body', function(){
|
||||
var data = {id:{key:123}, number:'9876'};
|
||||
xhr.expectGET("/CreditCard/123").respond(data);
|
||||
var cc = CreditCard.get({id:123});
|
||||
xhr.flush();
|
||||
expect(cc instanceof CreditCard).toBeTruthy();
|
||||
var idBefore = cc.id;
|
||||
|
||||
xhr.expectPOST("/CreditCard/123", data).respond('');
|
||||
cc.$save();
|
||||
xhr.flush();
|
||||
expect(idBefore).toEqual(cc.id);
|
||||
});
|
||||
|
||||
it('should bind default parameters', function(){
|
||||
xhr.expectGET('/CreditCard/123.visa?minimum=0.05').respond({id:123});
|
||||
var Visa = CreditCard.bind({verb:'.visa', minimum:0.05});
|
||||
|
|
|
|||
Loading…
Reference in a new issue