Skip to content

Commit b53f4b6

Browse files
author
Ivan Zubok
committed
fix fromServer param while copying
1 parent cd7d96c commit b53f4b6

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/restangular.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ restangular.provider('Restangular', function() {
7373
object.setPlainByDefault = function(value) {
7474
config.plainByDefault = value === true ? true : false;
7575
return this;
76-
}
76+
};
7777

7878
config.withHttpValues = function(httpLocalConfig, obj) {
7979
return _.defaults(obj, httpLocalConfig, config.defaultHttpFields);
@@ -962,7 +962,7 @@ restangular.provider('Restangular', function() {
962962
function copyRestangularizedElement(fromElement, toElement) {
963963
var copiedElement = angular.copy(fromElement, toElement);
964964
return restangularizeElem(copiedElement[config.restangularFields.parentResource],
965-
copiedElement, copiedElement[config.restangularFields.route], true);
965+
copiedElement, copiedElement[config.restangularFields.route], copiedElement[config.restangularFields.fromServer]);
966966
}
967967

968968
function restangularizeElem(parent, element, route, fromServer, collection, reqParams) {

test/restangularSpec.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ describe("Restangular", function() {
2727

2828
infoModel = {
2929
id: 0, text: "Some additional account information"
30-
}
30+
};
3131

3232
newAccount = {id: 44, user: "First User", amount: 45, transactions: []};
3333

34-
messages = [{id: 23, name: "Gonto"}, {id: 45, name: "John"}]
34+
messages = [{id: 23, name: "Gonto"}, {id: 45, name: "John"}];
3535

3636
accountsDoSomethingModel = { result: 1 };
3737

@@ -332,7 +332,7 @@ describe("Restangular", function() {
332332
it("Should decorate element both on server and local by default", function() {
333333

334334
Restangular.extendModel('accounts', function(account) {
335-
account.extended = function() {return true;}
335+
account.extended = function() {return true;};
336336
return account;
337337
});
338338

@@ -476,7 +476,7 @@ describe("Restangular", function() {
476476

477477
it("Shouldn't be restangularized by default", function() {
478478
Restangular.extendModel('accounts', function(account) {
479-
account.extended = function() {return true;}
479+
account.extended = function() {return true;};
480480
return account;
481481
});
482482

@@ -824,6 +824,21 @@ describe("Restangular", function() {
824824
copiedAccount.getRestangularUrl(); // invoke the method we are spying on
825825
expect(that).toBe(copiedAccount);
826826
});
827+
828+
it("should copy an object and 'fromServer' param should be the same with the copied object", function() {
829+
// with fromServer=true
830+
restangularAccount1.get().then(function(account) {
831+
var copiedAccount = Restangular.copy(account);
832+
expect(account.fromServer).toEqual(copiedAccount.fromServer);
833+
});
834+
835+
// with fromServer=false
836+
var account = Restangular.one('accounts', 123),
837+
copiedAccount = Restangular.copy(account);
838+
expect(account.fromServer).toEqual(copiedAccount.fromServer);
839+
840+
$httpBackend.flush();
841+
});
827842
});
828843

829844
describe("getRestangularUrl", function() {
@@ -1049,7 +1064,7 @@ describe("Restangular", function() {
10491064
});
10501065

10511066
it('does not use the id for single nested resource GET', function() {
1052-
Restangular.one('accounts', 1).one('info', 0, true).get()
1067+
Restangular.one('accounts', 1).one('info', 0, true).get();
10531068
$httpBackend.expectGET('/accounts/1/info');
10541069
$httpBackend.flush();
10551070
});

0 commit comments

Comments
 (0)