diff --git a/lib/models/application.js b/lib/models/application.js index d80736fc..fe2f370c 100644 --- a/lib/models/application.js +++ b/lib/models/application.js @@ -151,7 +151,7 @@ Application.register = function (owner, name, options, cb) { props[p] = options[p]; } } - Application.create(props, cb); + this.create(props, cb); }; /** @@ -176,7 +176,7 @@ Application.prototype.resetKeys = function (cb) { * @param {Error} err */ Application.resetKeys = function (appId, cb) { - Application.findById(appId, function (err, app) { + this.findById(appId, function (err, app) { if (err) { cb && cb(err, app); return; @@ -203,7 +203,7 @@ Application.resetKeys = function (appId, cb) { * @param {String} matched - The matching key */ Application.authenticate = function (appId, key, cb) { - Application.findById(appId, function (err, app) { + this.findById(appId, function (err, app) { if (err || !app) { cb && cb(err, null); return; @@ -220,8 +220,3 @@ Application.authenticate = function (appId, key, cb) { module.exports = Application; - - - - - diff --git a/test/model.application.test.js b/test/model.application.test.js index 55121a49..d27a4750 100644 --- a/test/model.application.test.js +++ b/test/model.application.test.js @@ -167,3 +167,34 @@ describe('Application', function () { }); }); +describe('Application subclass', function () { + it('should use subclass model name', function (done) { + var MyApp = Application.extend('MyApp'); + MyApp.attachTo(loopback.createDataSource({connector: loopback.Memory})); + MyApp.register('rfeng', 'MyApp2', + {description: 'My second mobile application'}, function (err, result) { + var app = result; + assert.equal(app.owner, 'rfeng'); + assert.equal(app.name, 'MyApp2'); + assert.equal(app.description, 'My second mobile application'); + assert(app.clientKey); + assert(app.javaScriptKey); + assert(app.restApiKey); + assert(app.windowsKey); + assert(app.masterKey); + assert(app.created); + assert(app.modified); + MyApp.findById(app.id, function (err, myApp) { + assert(!err); + assert(myApp); + + Application.findById(app.id, function (err, myApp) { + assert(!err); + assert(myApp === null); + done(err, myApp); + }); + }); + }); + }); +}); +