From 881b76bfc34ab9005bb5f63e5ca9e80a306ecd23 Mon Sep 17 00:00:00 2001 From: Devraj Mehta Date: Fri, 21 Nov 2014 18:06:27 -0500 Subject: [PATCH 1/2] add request suffix to requests without params Fixes #947 --- src/restangular.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/restangular.js b/src/restangular.js index 28e73584..a8d62bc2 100644 --- a/src/restangular.js +++ b/src/restangular.js @@ -720,7 +720,7 @@ module.provider('Restangular', function() { replace(/%20/g, (pctEncodeSpaces ? '%20' : '+')); } - if (!params) { return url; } + if (!params) { return url + (this.config.suffix || ''); } var parts = []; forEachSorted(params, function(value, key) { From 68a1c511e76785a9fc89050eb011736fc0a30bee Mon Sep 17 00:00:00 2001 From: "Mehta, Devraj" Date: Sun, 22 Feb 2015 21:58:22 -0500 Subject: [PATCH 2/2] added tests for urls with suffixes --- test/restangularSpec.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/test/restangularSpec.js b/test/restangularSpec.js index ae771da2..a6c83d0c 100644 --- a/test/restangularSpec.js +++ b/test/restangularSpec.js @@ -293,12 +293,41 @@ describe("Restangular", function() { }); - describe("With Url", function() { - it("Shouldn't add suffix to URL", function() { + describe("With Suffix", function() { + it("shouldn't add suffix to getRestangularUrl", function() { var suffixRestangular = Restangular.withConfig(function(RestangularConfigurer) { RestangularConfigurer.setRequestSuffix('.json'); }); + var collection = suffixRestangular.all('accounts'); + expect(collection.getRestangularUrl()).toBe('/accounts'); + expect(collection.one('1').getRestangularUrl()).toBe('/accounts/1'); + }); + + it("should add suffix to getRequestedUrl", function() { + var suffixRestangular = Restangular.withConfig(function(RestangularConfigurer) { + RestangularConfigurer.setRequestSuffix('.json'); + }); + var collection = suffixRestangular.all('accounts'); + expect(collection.getRequestedUrl()).toBe('/accounts.json'); + expect(collection.one('1').getRequestedUrl()).toBe('/accounts/1.json'); + }); + + it("should add suffix to request", function() { + var suffixRestangular = Restangular.withConfig(function(RestangularConfigurer) { + RestangularConfigurer.setRequestSuffix('.json'); + }); + var collection = suffixRestangular.all('accounts'); + $httpBackend.expectGET('/accounts.json').respond(200); + $httpBackend.expectGET('/accounts/1.json').respond(200); + collection.getList(); + collection.get('1'); + $httpBackend.flush(); + }); + it("shouldn't add suffix to allUrl", function() { + var suffixRestangular = Restangular.withConfig(function(RestangularConfigurer) { + RestangularConfigurer.setRequestSuffix('.json'); + }); $httpBackend.expectGET('http://accounts.com/all'); suffixRestangular.allUrl('accounts', 'http://accounts.com/all').getList(); $httpBackend.flush();