From 8c69435a6e85105caab4224f77e2bdb6a3e98121 Mon Sep 17 00:00:00 2001 From: Kostas Papadimitriou Date: Fri, 27 Mar 2015 01:56:37 +0200 Subject: [PATCH] Handle null/empty type paths in build url mixin handle empty values returned by pathForType in buildURL method of the build url mixin. refs emberjs/data#2844 --- .../ember-data/lib/adapters/build-url-mixin.js | 5 ++++- .../build-url-mixin/path-for-type-test.js | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/ember-data/lib/adapters/build-url-mixin.js b/packages/ember-data/lib/adapters/build-url-mixin.js index 5fe51135919..f23eee69a6b 100644 --- a/packages/ember-data/lib/adapters/build-url-mixin.js +++ b/packages/ember-data/lib/adapters/build-url-mixin.js @@ -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 diff --git a/packages/ember-data/tests/unit/adapters/build-url-mixin/path-for-type-test.js b/packages/ember-data/tests/unit/adapters/build-url-mixin/path-for-type-test.js index c2239fe5582..0ef1fbe8a52 100644 --- a/packages/ember-data/tests/unit/adapters/build-url-mixin/path-for-type-test.js +++ b/packages/ember-data/tests/unit/adapters/build-url-mixin/path-for-type-test.js @@ -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 @@ -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"); +});