Skip to content

Commit

Permalink
Merge pull request #2946 from vinilios/master
Browse files Browse the repository at this point in the history
Handle null/empty type paths in build url mixin
  • Loading branch information
igorT committed Apr 1, 2015
2 parents d85526c + 073686c commit 1be7a77
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 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,12 @@ 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 1be7a77

Please sign in to comment.