Skip to content

Commit

Permalink
fix fromServer param while copying
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Zubok committed Aug 31, 2016
1 parent cd7d96c commit b53f4b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/restangular.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ restangular.provider('Restangular', function() {
object.setPlainByDefault = function(value) {
config.plainByDefault = value === true ? true : false;
return this;
}
};

config.withHttpValues = function(httpLocalConfig, obj) {
return _.defaults(obj, httpLocalConfig, config.defaultHttpFields);
Expand Down Expand Up @@ -962,7 +962,7 @@ restangular.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);
copiedElement, copiedElement[config.restangularFields.route], copiedElement[config.restangularFields.fromServer]);
}

function restangularizeElem(parent, element, route, fromServer, collection, reqParams) {
Expand Down
25 changes: 20 additions & 5 deletions test/restangularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ describe("Restangular", function() {

infoModel = {
id: 0, text: "Some additional account information"
}
};

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

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

accountsDoSomethingModel = { result: 1 };

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

Restangular.extendModel('accounts', function(account) {
account.extended = function() {return true;}
account.extended = function() {return true;};
return account;
});

Expand Down Expand Up @@ -476,7 +476,7 @@ describe("Restangular", function() {

it("Shouldn't be restangularized by default", function() {
Restangular.extendModel('accounts', function(account) {
account.extended = function() {return true;}
account.extended = function() {return true;};
return account;
});

Expand Down Expand Up @@ -824,6 +824,21 @@ describe("Restangular", function() {
copiedAccount.getRestangularUrl(); // invoke the method we are spying on
expect(that).toBe(copiedAccount);
});

it("should copy an object and 'fromServer' param should be the same with the copied object", function() {
// with fromServer=true
restangularAccount1.get().then(function(account) {
var copiedAccount = Restangular.copy(account);
expect(account.fromServer).toEqual(copiedAccount.fromServer);
});

// with fromServer=false
var account = Restangular.one('accounts', 123),
copiedAccount = Restangular.copy(account);
expect(account.fromServer).toEqual(copiedAccount.fromServer);

$httpBackend.flush();
});
});

describe("getRestangularUrl", function() {
Expand Down Expand Up @@ -1049,7 +1064,7 @@ describe("Restangular", function() {
});

it('does not use the id for single nested resource GET', function() {
Restangular.one('accounts', 1).one('info', 0, true).get()
Restangular.one('accounts', 1).one('info', 0, true).get();
$httpBackend.expectGET('/accounts/1/info');
$httpBackend.flush();
});
Expand Down

0 comments on commit b53f4b6

Please sign in to comment.