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:
commit
de7133f57e
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue