Fix role.isOwner to support app-local registry

This commit is contained in:
Miroslav Bajtoš 2016-05-02 14:30:11 +02:00
parent 095dce0373
commit 35d9fa4b54
2 changed files with 28 additions and 6 deletions

View File

@ -145,12 +145,10 @@ module.exports = function(Role) {
});
function isUserClass(modelClass) {
if (modelClass) {
return modelClass === loopback.User ||
modelClass.prototype instanceof loopback.User;
} else {
return false;
}
if (!modelClass) return false;
var User = modelClass.modelBuilder.models.User;
if (!User) return false;
return modelClass == User || modelClass.prototype instanceof User;
}
/*!

View File

@ -434,4 +434,28 @@ describe('role model', function() {
});
});
});
describe('isOwner', function() {
it('supports app-local model registry', function(done) {
var app = loopback({ localRegistry: true, loadBuiltinModels: true });
app.dataSource('db', { connector: 'memory' });
// attach all auth-related models to 'db' datasource
app.enableAuth({ dataSource: 'db' });
var Role = app.models.Role;
var User = app.models.User;
var u = app.registry.findModel('User');
var credentials = { email: 'test@example.com', password: 'pass' };
User.create(credentials, function(err, user) {
if (err) return done(err);
Role.isOwner(User, user.id, user.id, function(err, result) {
if (err) return done(err);
expect(result, 'isOwner result').to.equal(true);
done();
});
});
});
});
});