diff --git a/src/restangular.js b/src/restangular.js index 28e73584..bd6fce77 100644 --- a/src/restangular.js +++ b/src/restangular.js @@ -932,8 +932,13 @@ module.provider('Restangular', function() { function copyRestangularizedElement(fromElement, toElement) { var copiedElement = angular.copy(fromElement, toElement); - return restangularizeElem(copiedElement[config.restangularFields.parentResource], - copiedElement, copiedElement[config.restangularFields.route], true); + if (fromElement.restangularCollection != null && fromElement.restangularCollection === true) { + return restangularizeCollection(copiedElement[config.restangularFields.parentResource], + copiedElement, copiedElement[config.restangularFields.route], true); + } else { + return restangularizeElem(copiedElement[config.restangularFields.parentResource], + copiedElement, copiedElement[config.restangularFields.route], true); + } } function restangularizeElem(parent, element, route, fromServer, collection, reqParams) { diff --git a/test/restangularSpec.js b/test/restangularSpec.js index ae771da2..47858004 100644 --- a/test/restangularSpec.js +++ b/test/restangularSpec.js @@ -557,6 +557,22 @@ describe("Restangular", function() { $httpBackend.flush(); }); + + it("putElement() should pass a restangularCollection to the callback", function() { + $httpBackend.expectGET('/accounts'); + restangularAccounts.getList().then(function(accounts) { + expect(accounts.restangularCollection).toBe(true); + accounts[1].amount += 1; + $httpBackend.expectPUT('/accounts/1'); + accounts.putElement(1).then(function(newAccounts) { + expect(newAccounts.restangularCollection).toBe(true); + expect(newAccounts.putElement).toBeDefined(); + expect(newAccounts[0].restangularCollection).toBe(false); + expect(newAccounts[1].restangularCollection).toBe(false); + }); + }); + $httpBackend.flush(); + }) }); describe("Scoped Service", function() {