From 1afc6229e477f9987a8f0e96c46ba8647fc7ddb7 Mon Sep 17 00:00:00 2001 From: lucioperca Date: Mon, 16 Jan 2017 17:10:36 -0800 Subject: [PATCH 1/3] test(ETags): Updated tests for ETag headers and setPlainByDefault --- test/restangularSpec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/restangularSpec.js b/test/restangularSpec.js index fd989819..3e9db68e 100644 --- a/test/restangularSpec.js +++ b/test/restangularSpec.js @@ -1593,25 +1593,25 @@ describe('Restangular', function () { describe('with ETag', function () { beforeEach(function () { - $httpBackend.whenGET('/accounts').respond( + $httpBackend.whenGET('/etagAccounts').respond( testData.accountsModel, {'ETag': 'c11ea3f8-3bfd-4be8-a6a6-501dd831b8a4'} ); - $httpBackend.whenGET('/accounts/1').respond( + $httpBackend.whenGET('/etagAccounts/1').respond( testData.accountsModel[1], {'ETag': 'bf79b780-f132-4f44-a9eb-7e6eb4f902b2'} ); }); it('should not add restangularized ETag to response object', function () { - plainByDefaultRestangular.one('accounts', 0).get().then(function (account) { + plainByDefaultRestangular.one('etagAccounts', 1).get().then(function (account) { expect(account).toEqual(testData.accountsModel[0]); }); $httpBackend.flush(); }); it('shoud not add restangularized ETag to response collection', function () { - plainByDefaultRestangular.all('accounts').getList().then(function (accounts) { + plainByDefaultRestangular.all('etagAccounts').getList().then(function (accounts) { expect(accounts).toEqual(testData.accountsModel); }); $httpBackend.flush(); From 9c916e46061f3923ff5d804d66232cec97c106d5 Mon Sep 17 00:00:00 2001 From: lucioperca Date: Mon, 16 Jan 2017 17:42:57 -0800 Subject: [PATCH 2/3] Omit etag field when setPlainByDefault is configured --- src/restangular.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/restangular.js b/src/restangular.js index ff7d5e24..082c5274 100644 --- a/src/restangular.js +++ b/src/restangular.js @@ -1148,6 +1148,7 @@ } if (true === config.plainByDefault) { + delete data[config.restangularFields.etag]; return resolvePromise(deferred, response, data, filledArray); } @@ -1249,6 +1250,7 @@ var data; if (true === config.plainByDefault) { + delete elem[config.restangularFields.etag]; return resolvePromise(deferred, response, elem, filledObject); } From 8b7b7b8337e5b6c7c40a4b04edc8a577d5f28c87 Mon Sep 17 00:00:00 2001 From: lucioperca Date: Mon, 16 Jan 2017 17:47:20 -0800 Subject: [PATCH 3/3] test(ETags): Fixed test for ETag headers and setPlainByDefault in response object --- test/restangularSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/restangularSpec.js b/test/restangularSpec.js index 3e9db68e..f4a2017e 100644 --- a/test/restangularSpec.js +++ b/test/restangularSpec.js @@ -1605,7 +1605,7 @@ describe('Restangular', function () { it('should not add restangularized ETag to response object', function () { plainByDefaultRestangular.one('etagAccounts', 1).get().then(function (account) { - expect(account).toEqual(testData.accountsModel[0]); + expect(account).toEqual(testData.accountsModel[1]); }); $httpBackend.flush(); });