Customize/Normalize class-level remoting http path
This commit is contained in:
parent
1247c449b2
commit
71bf0f8240
|
@ -110,7 +110,17 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
|
|||
var args = slice.call(arguments);
|
||||
var pluralName = (settings && settings.plural) ||
|
||||
inflection.pluralize(className);
|
||||
|
||||
|
||||
var pathName = (settings && settings.path) || pluralName;
|
||||
var normalize = ModelBuilder.normalizePathName === true || (settings && settings.normalize);
|
||||
|
||||
if (this.normalizePathName || (normalize && this.normalizePathName !== false)) {
|
||||
pathName = inflection.transform(pathName, ['underscore', 'dasherize']);
|
||||
} else if (typeof ModelBuilder.normalizePathName === 'function' &&
|
||||
this.normalizePathName !== false) {
|
||||
pathName = ModelBuilder.normalizePathName.apply(this, [pathName].concat(args));
|
||||
}
|
||||
|
||||
if (!className) {
|
||||
throw new Error('Class name required');
|
||||
}
|
||||
|
@ -188,7 +198,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
|
|||
hiddenProperty(ModelClass, 'dataSource', modelBuilder); // Keep for back-compatibility
|
||||
hiddenProperty(ModelClass, 'pluralModelName', pluralName);
|
||||
hiddenProperty(ModelClass, 'relations', {});
|
||||
hiddenProperty(ModelClass, 'http', { path: '/' + pluralName });
|
||||
hiddenProperty(ModelClass, 'http', { path: '/' + pathName });
|
||||
hiddenProperty(ModelClass, 'base', ModelBaseClass);
|
||||
|
||||
// inherit ModelBaseClass static methods
|
||||
|
|
|
@ -548,6 +548,28 @@ describe('DataSource define model', function () {
|
|||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should allow an explicit remoting path', function () {
|
||||
var ds = new DataSource('memory');
|
||||
|
||||
var User = ds.define('User', {name: String, bio: String}, { path: 'accounts' });
|
||||
User.http.path.should.equal('/accounts');
|
||||
});
|
||||
|
||||
it('should normalize the remoting path - option', function () {
|
||||
var ds = new DataSource('memory');
|
||||
|
||||
var User = ds.define('UserAccount', {name: String, bio: String}, { normalize: true });
|
||||
User.http.path.should.equal('/user-accounts');
|
||||
});
|
||||
|
||||
it('should normalize the remoting path - modelBuilder', function () {
|
||||
var ds = new DataSource('memory');
|
||||
ds.modelBuilder.normalizePathName = true;
|
||||
|
||||
var User = ds.define('UserAccount', {name: String, bio: String});
|
||||
User.http.path.should.equal('/user-accounts');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue