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

Don't copy server response to resource value if they are already the same object #4508

Closed
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
2 changes: 1 addition & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ angular.module('ngResource', ['ng']).
value.push(new Resource(item));
});
} else {
copy(data, value);
if(data !== value) copy(data, value);
value.$promise = promise;
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ describe("resource", function() {
expect(idBefore).toEqual(cc.id);
});

it('should not throw if response.data is the resource object', function() {
var data = {id:{key:123}, number:'9876'};
$httpBackend.expect('GET', '/CreditCard/123').respond(data);

var cc = CreditCard.get({id:123});
$httpBackend.flush();
expect(cc instanceof CreditCard).toBe(true);

$httpBackend.expect('POST', '/CreditCard/123', angular.toJson(data)).respond(cc);

expect(function() {
cc.$save();
$httpBackend.flush();
}).not.toThrow();
});

it('should bind default parameters', function() {
$httpBackend.expect('GET', '/CreditCard/123.visa?minimum=0.05').respond({id: 123});
Expand Down