diff --git a/src/restangular.js b/src/restangular.js index 5f41e7f0..bf408f99 100644 --- a/src/restangular.js +++ b/src/restangular.js @@ -720,7 +720,7 @@ restangular.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) { 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();