Skip to content

Commit

Permalink
Merge pull request #4108 from HeroicEric/fix-4105
Browse files Browse the repository at this point in the history
[BUGFIX beta] Fix `BuildUrlMixin.urlPrefix` regression when host=/
  • Loading branch information
bmac committed Jan 21, 2016
2 parents 9ba3b0d + 89f124b commit 10843fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion addon/-private/adapters/build-url-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,13 @@ export default Ember.Mixin.create({
@return {String} urlPrefix
*/
urlPrefix(path, parentURL) {
var host = get(this, 'host') || '';
var host = get(this, 'host');
var namespace = get(this, 'namespace');

if (!host || host === '/') {
host = '';
}

if (path) {
// Protocol relative url
if (/^\/\//.test(path) || /http(s)?:\/\//.test(path)) {
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/adapter/build-url-mixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ test('buildURL - with absolute paths in links and protocol relative host', funct
}));
});

test('buildURL - with absolute paths in links and host is /', function(assert) {
run(function() {
adapter.setProperties({
host: '/',
namespace: 'api/v1'
});
});
Post.reopen({ comments: DS.hasMany('comment', { async: true }) });
Comment.reopen({ post: DS.belongsTo('post', { async: false }) });

ajaxResponse({ posts: [{ id: 1, links: { comments: '/api/v1/posts/1/comments' } }] });

run(store, 'findRecord', 'post', 1).then(assert.wait(function(post) {
ajaxResponse({ comments: [{ id: 1 }] });
return post.get('comments');
})).then(assert.wait(function (comments) {
assert.equal(passedUrl, '/api/v1/posts/1/comments', 'host stripped out properly');
}));
});

test('buildURL - with full URLs in links', function(assert) {
adapter.setProperties({
host: 'http://example.com',
Expand Down

0 comments on commit 10843fc

Please sign in to comment.