Skip to content

Commit

Permalink
Handle null type paths
Browse files Browse the repository at this point in the history
handle empty values returned by pathForType in buildURL method of
the build url mixin.

refs emberjs#2844
  • Loading branch information
vinilios committed Mar 27, 2015
1 parent b421b88 commit 8b2cf85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/ember-data/lib/adapters/build-url-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ export default Ember.Mixin.create({
var url = [];
var host = get(this, 'host');
var prefix = this.urlPrefix();
var path;

if (type) { url.push(this.pathForType(type)); }
if (type && (path = this.pathForType(type))) {
if (path) { url.push(path); }
}

//We might get passed in an array of ids from findMany
//in which case we don't want to modify the url, as the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ var env, adapter;

module("unit/adapters/build-url-mixin/path-for-type - DS.BuildURLMixin#pathForType", {
setup: function() {
var Adapter = DS.Adapter.extend(DS.BuildURLMixin);

// test for overriden pathForType methods which return null path values
var customPathForType = {
pathForType: function(type) {
if (type === 'rootModel') { return ''; }
return this._super(type);
}
};

var Adapter = DS.Adapter.extend(DS.BuildURLMixin, customPathForType);

env = setupStore({
adapter: Adapter
Expand All @@ -23,3 +32,7 @@ test('pathForType - works with dasherized types', function() {
test('pathForType - works with underscored types', function() {
equal(adapter.pathForType('super_user'), "superUsers");
});

test('buildURL - works with empty paths', function() {
equal(adapter.buildURL('rootModel', 1), "/1");
});

0 comments on commit 8b2cf85

Please sign in to comment.