From c609b6d7ce3970cc76575025d5600ac4166a37d5 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 24 Apr 2015 08:23:13 -0700 Subject: [PATCH] Allow leading slash for `path` in model settings --- lib/model-builder.js | 6 +++++- test/loopback-dl.test.js | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/model-builder.js b/lib/model-builder.js index 9450dcbc..89b5f765 100644 --- a/lib/model-builder.js +++ b/lib/model-builder.js @@ -218,7 +218,11 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett hiddenProperty(ModelClass, 'dataSource', null); // Keep for back-compatibility hiddenProperty(ModelClass, 'pluralModelName', pluralName); hiddenProperty(ModelClass, 'relations', {}); - hiddenProperty(ModelClass, 'http', { path: '/' + pathName }); + if (pathName[0] !== '/') { + // Support both flavors path: 'x' and path: '/x' + pathName = '/' + pathName; + } + hiddenProperty(ModelClass, 'http', { path: pathName }); hiddenProperty(ModelClass, 'base', ModelBaseClass); hiddenProperty(ModelClass, '_observers', {}); diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index f360e4b1..d2eddd82 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -643,6 +643,15 @@ describe('DataSource define model', function () { User.http.path.should.equal('/accounts'); }); + it('should allow an explicit remoting path with leading /', function () { + var ds = new DataSource('memory'); + + var User = ds.define('User', {name: String, bio: String}, { + http: { path: '/accounts' } + }); + User.http.path.should.equal('/accounts'); + }); + }); describe('Load models with base', function () {