Merge pull request #139 from strongloop/feature/fix-app-model

Make sure methods are called in the context of the calling class
This commit is contained in:
Raymond Feng 2014-01-14 15:50:36 -08:00
commit de7133f57e
2 changed files with 34 additions and 8 deletions

View File

@ -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;

View File

@ -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);
});
});
});
});
});