Merge pull request #573 from strongloop/feature/allow-leading-slash-for-http-path

Allow leading slash for `path` in model settings
This commit is contained in:
Raymond Feng 2015-04-24 08:46:09 -07:00
commit f5dc38396a
2 changed files with 14 additions and 1 deletions

View File

@ -218,7 +218,11 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
hiddenProperty(ModelClass, 'dataSource', null); // Keep for back-compatibility hiddenProperty(ModelClass, 'dataSource', null); // Keep for back-compatibility
hiddenProperty(ModelClass, 'pluralModelName', pluralName); hiddenProperty(ModelClass, 'pluralModelName', pluralName);
hiddenProperty(ModelClass, 'relations', {}); 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, 'base', ModelBaseClass);
hiddenProperty(ModelClass, '_observers', {}); hiddenProperty(ModelClass, '_observers', {});

View File

@ -643,6 +643,15 @@ describe('DataSource define model', function () {
User.http.path.should.equal('/accounts'); 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 () { describe('Load models with base', function () {