Skip to content

Commit

Permalink
whoops! testing for the wrong things, sorry everybody!
Browse files Browse the repository at this point in the history
  • Loading branch information
emuvente committed Feb 2, 2016
1 parent 5f6949f commit 70b0441
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/backbone.siren.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,8 @@ BbSiren.prototype = {
, getRootForPath: function (path) {
// remove parameters an anchor tags from path
var strippedPath = path.split(/[\?#]/)[0];
// grab the parent path (0 is "", 1 is parent)
var strippedPathParent = '/' + strippedPath.split('/')[1];
// grab the parent path
var strippedPathParent = strippedPath.split('/')[0];
return this.alternateRoots[strippedPath] ? this.alternateRoots[strippedPath] : this.alternateRoots[strippedPathParent] ? this.alternateRoots[strippedPathParent] : this.apiRoot;
}

Expand Down
26 changes: 13 additions & 13 deletions test/spec/backbone.siren.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,45 +575,45 @@ describe('Backbone.Siren: ', function () {
it('strips the parameters from the path when checking for root path', function() {
var sirenApi = new Backbone.Siren('/api');
sirenApi.alternateRoots = {
'/my/route': '/right'
,'/my/route?params': '/wrong'
,'/my/route#anchor': '/also-wrong'
,'/my/route?params#anchor': '/you-are-never-going-to-pass-this-test'
'my/route': '/right'
,'my/route?params': '/wrong'
,'my/route#anchor': '/also-wrong'
,'my/route?params#anchor': '/you-are-never-going-to-pass-this-test'
};

expect(sirenApi.getRootForPath('/my/route?params')).toBe('/right');
expect(sirenApi.getRootForPath('/my/route#anchor')).toBe('/right');
expect(sirenApi.getRootForPath('/my/route?params#anchor')).toBe('/right');
expect(sirenApi.getRootForPath('my/route?params')).toBe('/right');
expect(sirenApi.getRootForPath('my/route#anchor')).toBe('/right');
expect(sirenApi.getRootForPath('my/route?params#anchor')).toBe('/right');
});


it('returns the default root when no alternate root is found for the path', function() {
var sirenApi = new Backbone.Siren('/right');
sirenApi.alternateRoots = {
'/my/other-route': '/wrong'
'my/other-route': '/wrong'
};

expect(sirenApi.getRootForPath('/my/route')).toBe('/right');
expect(sirenApi.getRootForPath('my/route')).toBe('/right');
});


it('returns the alternate root for the path', function() {
var sirenApi = new Backbone.Siren('/wrong');
sirenApi.alternateRoots = {
'/my/route': '/right'
'my/route': '/right'
};

expect(sirenApi.getRootForPath('/my/route')).toBe('/right');
expect(sirenApi.getRootForPath('my/route')).toBe('/right');
});


it('returns the root for the parent of the path when a root is not known for the path', function() {
var sirenApi = new Backbone.Siren('/wrong');
sirenApi.alternateRoots = {
'/parent': '/right'
'parent': '/right'
};

expect(sirenApi.getRootForPath('/parent/child')).toBe('/right');
expect(sirenApi.getRootForPath('parent/child')).toBe('/right');
});
});

Expand Down

0 comments on commit 70b0441

Please sign in to comment.