Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle null/empty type paths in build url mixin #2946

Merged
merged 1 commit into from
Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});