Merge pull request #2551 from strongloop/fix/global-registry-in-fixtures
test: use local registry in test fixtures
This commit is contained in:
commit
ea21169da0
|
@ -268,7 +268,7 @@ module.exports = function(ACL) {
|
|||
* @return {Object[]} An array of ACLs
|
||||
*/
|
||||
ACL.getStaticACLs = function getStaticACLs(model, property) {
|
||||
var modelClass = loopback.findModel(model);
|
||||
var modelClass = this.registry.findModel(model);
|
||||
var staticACLs = [];
|
||||
if (modelClass && modelClass.settings.acls) {
|
||||
modelClass.settings.acls.forEach(function(acl) {
|
||||
|
@ -361,7 +361,7 @@ module.exports = function(ACL) {
|
|||
acls = acls.concat(dynACLs);
|
||||
resolved = self.resolvePermission(acls, req);
|
||||
if (resolved && resolved.permission === ACL.DEFAULT) {
|
||||
var modelClass = loopback.findModel(model);
|
||||
var modelClass = self.registry.findModel(model);
|
||||
resolved.permission = (modelClass && modelClass.settings.defaultPermission) || ACL.ALLOW;
|
||||
}
|
||||
if (callback) callback(null, resolved);
|
||||
|
|
|
@ -144,7 +144,7 @@ module.exports = function(Change) {
|
|||
*/
|
||||
|
||||
Change.findOrCreateChange = function(modelName, modelId, callback) {
|
||||
assert(loopback.findModel(modelName), modelName + ' does not exist');
|
||||
assert(this.registry.findModel(modelName), modelName + ' does not exist');
|
||||
callback = callback || utils.createPromiseCallback();
|
||||
var id = this.idForModel(modelName, modelId);
|
||||
var Change = this;
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
"principalType": "ROLE",
|
||||
"principalId": "$owner",
|
||||
"permission": "ALLOW",
|
||||
"property": "updateAttributes"
|
||||
"property": "patchAttributes"
|
||||
},
|
||||
{
|
||||
"principalType": "ROLE",
|
||||
|
|
|
@ -397,6 +397,9 @@ describe('AccessToken', function() {
|
|||
});
|
||||
|
||||
describe('app.enableAuth()', function() {
|
||||
beforeEach(function setupAuthWithModels() {
|
||||
app.enableAuth({ dataSource: ds });
|
||||
});
|
||||
beforeEach(createTestingToken);
|
||||
|
||||
it('prevents remote call with 401 status on denied ACL', function(done) {
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
"_meta": {
|
||||
"sources": [
|
||||
"../common/models",
|
||||
"./models"
|
||||
"./models",
|
||||
"../../../../common/models"
|
||||
]
|
||||
},
|
||||
"ACL": {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
var loopback = require('../../../..');
|
||||
var boot = require('loopback-boot');
|
||||
var app = module.exports = loopback();
|
||||
var app = module.exports = loopback({ localRegistry: true });
|
||||
var errorHandler = require('strong-error-handler');
|
||||
boot(app, __dirname);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
var loopback = require('../../../../index');
|
||||
var app = module.exports = loopback();
|
||||
var app = module.exports = loopback({ localRegistry: true });
|
||||
var models = require('./models');
|
||||
var TestModel = models.TestModel;
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
"_meta": {
|
||||
"sources": [
|
||||
"../common/models",
|
||||
"./models"
|
||||
"./models",
|
||||
"../../../../common/models"
|
||||
]
|
||||
},
|
||||
"User": {
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
"_meta": {
|
||||
"sources": [
|
||||
"../common/models",
|
||||
"./models"
|
||||
"./models",
|
||||
"../../../../common/models"
|
||||
]
|
||||
},
|
||||
"ACL": {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
var loopback = require('../../../../index');
|
||||
var boot = require('loopback-boot');
|
||||
var app = module.exports = loopback();
|
||||
var app = module.exports = loopback({ localRegistry: true });
|
||||
var errorHandler = require('strong-error-handler');
|
||||
|
||||
boot(app, __dirname);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "post",
|
||||
"name": "Post",
|
||||
"base": "PersistedModel",
|
||||
"properties": {
|
||||
"title": {
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
"_meta": {
|
||||
"sources": [
|
||||
"../common/models",
|
||||
"./models"
|
||||
"./models",
|
||||
"../../../../common/models"
|
||||
]
|
||||
},
|
||||
"Email": {
|
||||
|
@ -14,7 +15,7 @@
|
|||
"public": true,
|
||||
"relations": {
|
||||
"posts": {
|
||||
"model": "post",
|
||||
"model": "Post",
|
||||
"type": "hasMany",
|
||||
"foreignKey": "userId"
|
||||
}
|
||||
|
@ -51,7 +52,7 @@
|
|||
"dataSource": "db",
|
||||
"public": true
|
||||
},
|
||||
"post": {
|
||||
"Post": {
|
||||
"dataSource": "db",
|
||||
"public": true
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
var loopback = require('../../../../index');
|
||||
var boot = require('loopback-boot');
|
||||
var app = module.exports = loopback();
|
||||
var app = module.exports = loopback({ localRegistry: true });
|
||||
var errorHandler = require('strong-error-handler');
|
||||
app.enableAuth();
|
||||
boot(app, __dirname);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
var async = require('async');
|
||||
var loopback = require('../');
|
||||
var ACL = loopback.ACL;
|
||||
var Change = loopback.Change;
|
||||
var defineModelTestsWithDataSource = require('./util/model-tests');
|
||||
var PersistedModel = loopback.PersistedModel;
|
||||
|
||||
|
@ -74,7 +73,10 @@ describe.onServer('Remote Methods', function() {
|
|||
var User, Post, dataSource, app;
|
||||
|
||||
beforeEach(function() {
|
||||
User = PersistedModel.extend('user', {
|
||||
app = loopback({ localRegistry: true, loadBuiltinModels: true });
|
||||
app.set('remoting', { errorHandler: { debug: true, log: false }});
|
||||
|
||||
User = app.registry.createModel('user', {
|
||||
id: { id: true, type: String, defaultFn: 'guid' },
|
||||
'first': String,
|
||||
'last': String,
|
||||
|
@ -87,7 +89,7 @@ describe.onServer('Remote Methods', function() {
|
|||
trackChanges: true,
|
||||
});
|
||||
|
||||
Post = PersistedModel.extend('post', {
|
||||
Post = app.registry.createModel('post', {
|
||||
id: { id: true, type: String, defaultFn: 'guid' },
|
||||
title: String,
|
||||
content: String,
|
||||
|
@ -95,12 +97,10 @@ describe.onServer('Remote Methods', function() {
|
|||
trackChanges: true,
|
||||
});
|
||||
|
||||
dataSource = loopback.createDataSource({
|
||||
connector: loopback.Memory,
|
||||
});
|
||||
dataSource = app.dataSource('db', { connector: 'memory' });
|
||||
|
||||
User.attachTo(dataSource);
|
||||
Post.attachTo(dataSource);
|
||||
app.model(User, { dataSource: 'db' });
|
||||
app.model(Post, { dataSource: 'db' });
|
||||
|
||||
User.hasMany(Post);
|
||||
|
||||
|
@ -112,22 +112,16 @@ describe.onServer('Remote Methods', function() {
|
|||
}
|
||||
};
|
||||
|
||||
loopback.remoteMethod(
|
||||
User.login,
|
||||
{
|
||||
accepts: [
|
||||
{ arg: 'username', type: 'string', required: true },
|
||||
{ arg: 'password', type: 'string', required: true },
|
||||
],
|
||||
returns: { arg: 'sessionId', type: 'any', root: true },
|
||||
http: { path: '/sign-in', verb: 'get' },
|
||||
}
|
||||
);
|
||||
User.remoteMethod('login', {
|
||||
accepts: [
|
||||
{ arg: 'username', type: 'string', required: true },
|
||||
{ arg: 'password', type: 'string', required: true },
|
||||
],
|
||||
returns: { arg: 'sessionId', type: 'any', root: true },
|
||||
http: { path: '/sign-in', verb: 'get' },
|
||||
});
|
||||
|
||||
app = loopback();
|
||||
app.set('remoting', { errorHandler: { debug: true, log: false }});
|
||||
app.use(loopback.rest());
|
||||
app.model(User);
|
||||
});
|
||||
|
||||
describe('Model.destroyAll(callback)', function() {
|
||||
|
@ -549,7 +543,7 @@ describe.onServer('Remote Methods', function() {
|
|||
it('Get the Change Model', function() {
|
||||
var UserChange = User.getChangeModel();
|
||||
var change = new UserChange();
|
||||
assert(change instanceof Change);
|
||||
assert(change instanceof app.registry.getModel('Change'));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -14,16 +14,10 @@ describe('users - integration', function() {
|
|||
lt.beforeEach.withApp(app);
|
||||
|
||||
before(function(done) {
|
||||
// HACK: [rfeng] We have to reset the relations as they are polluted by
|
||||
// other tests
|
||||
app.models.User.hasMany(app.models.post);
|
||||
app.models.User.hasMany(app.models.AccessToken,
|
||||
{ options: { disableInclude: true }});
|
||||
app.models.AccessToken.belongsTo(app.models.User);
|
||||
app.models.User.destroyAll(function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
app.models.post.destroyAll(function(err) {
|
||||
app.models.Post.destroyAll(function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
app.models.blog.destroyAll(function(err) {
|
||||
|
|
Loading…
Reference in New Issue