Skip to content

Commit

Permalink
Merge pull request #130 from knownasilya/patch-1
Browse files Browse the repository at this point in the history
Handling urls types with slash before ?
  • Loading branch information
samselikoff committed May 20, 2015
2 parents d02d2c9 + 1c5197a commit d63d195
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion addon/shorthands/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export default {

getTypeFromUrl: function(url, hasId) {
var urlNoId = hasId ? url.substr(0, url.lastIndexOf('/')) : url;
var urlNoIdNoQuery = urlNoId.split("?")[0];
var urlSplit = urlNoId.split("?");
var urlNoIdNoQuery = urlSplit[0].slice(-1) === '/' ? urlSplit[0].slice(0, -1) : urlSplit[0];
var type = singularize(urlNoIdNoQuery.substr(urlNoIdNoQuery.lastIndexOf('/') + 1));

return type;
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/shorthands/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ test('it returns a string if it\'s a string', function(assert) {
request.params.id = "someID";
assert.equal(utils.getIdForRequest(request), "someID", 'it returns a number');
});

test('url without id returns correct type', function (assert) {
var urlWithSlash = '/api/users/?test=true';
var urlWithoutSlash = '/api/users?test=true';

assert.equal(utils.getTypeFromUrl(urlWithSlash), 'user', 'it returns a singular type');
assert.equal(utils.getTypeFromUrl(urlWithoutSlash), 'user', 'it returns a singular type');
});

0 comments on commit d63d195

Please sign in to comment.