Skip to content

Commit

Permalink
Merge pull request #948 from devm33/master
Browse files Browse the repository at this point in the history
add request suffix to requests without params
  • Loading branch information
grabbou committed Feb 23, 2015
2 parents cbe6d17 + 68a1c51 commit 217f8a5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/restangular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
33 changes: 31 additions & 2 deletions test/restangularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 217f8a5

Please sign in to comment.