mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 09:50:34 +03:00
Merge pull request #6696 from ErisDS/fixture-migration-amends
Improve code for handling fixture migrations
This commit is contained in:
commit
9a674018b0
@ -48,18 +48,18 @@
|
|||||||
{
|
{
|
||||||
"name": "Role",
|
"name": "Role",
|
||||||
"entries": [
|
"entries": [
|
||||||
{
|
{
|
||||||
"name": "Administrator",
|
"name": "Administrator",
|
||||||
"description": "Administrators"
|
"description": "Administrators"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Editor",
|
"name": "Editor",
|
||||||
"description": "Editors"
|
"description": "Editors"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Author",
|
"name": "Author",
|
||||||
"description": "Authors"
|
"description": "Authors"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Owner",
|
"name": "Owner",
|
||||||
"description": "Blog Owner"
|
"description": "Blog Owner"
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// This module handles populating fixtures on a fresh install.
|
// This module handles populating fixtures on a fresh install.
|
||||||
// This is done automatically, by reading the fixtures.json file
|
// This is done automatically, by reading the fixtures.json file
|
||||||
// All models, and relationships inside the file are then setup.
|
// All models, and relationships inside the file are then setup.
|
||||||
|
|
||||||
var Promise = require('bluebird'),
|
var Promise = require('bluebird'),
|
||||||
models = require('../../../models'),
|
models = require('../../../models'),
|
||||||
coreUtils = require('../../../utils'),
|
coreUtils = require('../../../utils'),
|
||||||
|
@ -7,8 +7,9 @@ var _ = require('lodash'),
|
|||||||
|
|
||||||
fixtures = require('./fixtures'),
|
fixtures = require('./fixtures'),
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
matchFunc,
|
matchFunc,
|
||||||
|
matchObj,
|
||||||
fetchRelationData,
|
fetchRelationData,
|
||||||
findRelationFixture,
|
findRelationFixture,
|
||||||
findModelFixture,
|
findModelFixture,
|
||||||
@ -18,7 +19,7 @@ var _ = require('lodash'),
|
|||||||
addFixturesForModel,
|
addFixturesForModel,
|
||||||
addFixturesForRelation,
|
addFixturesForRelation,
|
||||||
findModelFixtureEntry,
|
findModelFixtureEntry,
|
||||||
findPermissionModelForObject,
|
findModelFixtures,
|
||||||
findPermissionRelationsForObject;
|
findPermissionRelationsForObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,6 +55,20 @@ matchFunc = function matchFunc(match, key, value) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
matchObj = function matchObj(match, item) {
|
||||||
|
var matchObj = {};
|
||||||
|
|
||||||
|
if (_.isArray(match)) {
|
||||||
|
_.each(match, function (matchProp) {
|
||||||
|
matchObj[matchProp] = item.get(matchProp);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
matchObj[match] = item.get(match);
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchObj;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ### Fetch Relation Data
|
* ### Fetch Relation Data
|
||||||
* Before we build relations we need to fetch all of the models from both sides so that we can
|
* Before we build relations we need to fetch all of the models from both sides so that we can
|
||||||
@ -63,10 +78,11 @@ matchFunc = function matchFunc(match, key, value) {
|
|||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
fetchRelationData = function fetchRelationData(relation) {
|
fetchRelationData = function fetchRelationData(relation) {
|
||||||
var props = {
|
var fromOptions = _.extend({}, modelOptions, {withRelated: [relation.from.relation]}),
|
||||||
from: models[relation.from.model].findAll(modelOptions),
|
props = {
|
||||||
to: models[relation.to.model].findAll(modelOptions)
|
from: models[relation.from.model].findAll(fromOptions),
|
||||||
};
|
to: models[relation.to.model].findAll(modelOptions)
|
||||||
|
};
|
||||||
|
|
||||||
return Promise.props(props);
|
return Promise.props(props);
|
||||||
};
|
};
|
||||||
@ -81,7 +97,13 @@ fetchRelationData = function fetchRelationData(relation) {
|
|||||||
*/
|
*/
|
||||||
addFixturesForModel = function addFixturesForModel(modelFixture) {
|
addFixturesForModel = function addFixturesForModel(modelFixture) {
|
||||||
return Promise.mapSeries(modelFixture.entries, function (entry) {
|
return Promise.mapSeries(modelFixture.entries, function (entry) {
|
||||||
return models[modelFixture.name].add(entry, modelOptions);
|
return models[modelFixture.name].findOne(entry, modelOptions).then(function (found) {
|
||||||
|
if (!found) {
|
||||||
|
return models[modelFixture.name].add(entry, modelOptions);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).then(function (results) {
|
||||||
|
return {expected: modelFixture.entries.length, done: _.compact(results).length};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -94,23 +116,34 @@ addFixturesForModel = function addFixturesForModel(modelFixture) {
|
|||||||
* @returns {Promise.<*>}
|
* @returns {Promise.<*>}
|
||||||
*/
|
*/
|
||||||
addFixturesForRelation = function addFixturesForRelation(relationFixture) {
|
addFixturesForRelation = function addFixturesForRelation(relationFixture) {
|
||||||
return fetchRelationData(relationFixture).then(function getRelationOps(data) {
|
var ops = [], max = 0;
|
||||||
var ops = [];
|
|
||||||
|
|
||||||
|
return fetchRelationData(relationFixture).then(function getRelationOps(data) {
|
||||||
_.each(relationFixture.entries, function processEntries(entry, key) {
|
_.each(relationFixture.entries, function processEntries(entry, key) {
|
||||||
var fromItem = data.from.find(matchFunc(relationFixture.from.match, key));
|
var fromItem = data.from.find(matchFunc(relationFixture.from.match, key));
|
||||||
|
|
||||||
_.each(entry, function processEntryValues(value, key) {
|
_.each(entry, function processEntryValues(value, key) {
|
||||||
var toItem = data.to.filter(matchFunc(relationFixture.to.match, key, value));
|
var toItems = data.to.filter(matchFunc(relationFixture.to.match, key, value));
|
||||||
if (toItem) {
|
max += toItems.length;
|
||||||
ops.push(function addRelationItem() {
|
|
||||||
return fromItem[relationFixture.from.relation]().attach(toItem);
|
// Remove any duplicates that already exist in the collection
|
||||||
|
toItems = _.reject(toItems, function (item) {
|
||||||
|
return fromItem
|
||||||
|
.related(relationFixture.from.relation)
|
||||||
|
.findWhere(matchObj(relationFixture.to.match, item));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (toItems && toItems.length > 0) {
|
||||||
|
ops.push(function addRelationItems() {
|
||||||
|
return fromItem[relationFixture.from.relation]().attach(toItems);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return sequence(ops);
|
return sequence(ops);
|
||||||
|
}).then(function (result) {
|
||||||
|
return {expected: max, done: _(result).map('length').sum()};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -139,13 +172,13 @@ findModelFixtureEntry = function findModelFixtureEntry(modelName, matchExpr) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ### Find All Model Fixture
|
* ### Find Model Fixtures
|
||||||
* Find a model fixture name & a matching expression for the FILTER function
|
* Find a model fixture name & a matching expression for the FILTER function
|
||||||
* @param {String} modelName
|
* @param {String} modelName
|
||||||
* @param {String|Object|Function} matchExpr
|
* @param {String|Object|Function} matchExpr
|
||||||
* @returns {Object} model fixture
|
* @returns {Object} model fixture
|
||||||
*/
|
*/
|
||||||
findPermissionModelForObject = function findPermissionModelForObject(modelName, matchExpr) {
|
findModelFixtures = function findModelFixtures(modelName, matchExpr) {
|
||||||
var foundModel = _.cloneDeep(findModelFixture(modelName));
|
var foundModel = _.cloneDeep(findModelFixture(modelName));
|
||||||
foundModel.entries = _.filter(foundModel.entries, matchExpr);
|
foundModel.entries = _.filter(foundModel.entries, matchExpr);
|
||||||
return foundModel;
|
return foundModel;
|
||||||
@ -194,7 +227,7 @@ module.exports = {
|
|||||||
addFixturesForModel: addFixturesForModel,
|
addFixturesForModel: addFixturesForModel,
|
||||||
addFixturesForRelation: addFixturesForRelation,
|
addFixturesForRelation: addFixturesForRelation,
|
||||||
findModelFixtureEntry: findModelFixtureEntry,
|
findModelFixtureEntry: findModelFixtureEntry,
|
||||||
findPermissionModelForObject: findPermissionModelForObject,
|
findModelFixtures: findModelFixtures,
|
||||||
findPermissionRelationsForObject: findPermissionRelationsForObject,
|
findPermissionRelationsForObject: findPermissionRelationsForObject,
|
||||||
modelOptions: modelOptions
|
modelOptions: modelOptions
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,8 @@ Role = ghostBookshelf.Model.extend({
|
|||||||
// whitelists for the `options` hash argument on methods, by method name.
|
// whitelists for the `options` hash argument on methods, by method name.
|
||||||
// these are the only options that can be passed to Bookshelf / Knex.
|
// these are the only options that can be passed to Bookshelf / Knex.
|
||||||
validOptions = {
|
validOptions = {
|
||||||
findOne: ['withRelated']
|
findOne: ['withRelated'],
|
||||||
|
findAll: ['withRelated']
|
||||||
};
|
};
|
||||||
|
|
||||||
if (validOptions[methodName]) {
|
if (validOptions[methodName]) {
|
||||||
|
@ -11,6 +11,11 @@ var testUtils = require('../utils'),
|
|||||||
sandbox = sinon.sandbox.create();
|
sandbox = sinon.sandbox.create();
|
||||||
|
|
||||||
describe('Database Migration (special functions)', function () {
|
describe('Database Migration (special functions)', function () {
|
||||||
|
var loggerStub = {
|
||||||
|
info: sandbox.stub(),
|
||||||
|
warn: sandbox.stub()
|
||||||
|
};
|
||||||
|
|
||||||
before(testUtils.teardown);
|
before(testUtils.teardown);
|
||||||
afterEach(testUtils.teardown);
|
afterEach(testUtils.teardown);
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
@ -18,8 +23,6 @@ describe('Database Migration (special functions)', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Fixtures', function () {
|
describe('Fixtures', function () {
|
||||||
beforeEach(testUtils.setup());
|
|
||||||
|
|
||||||
// Custom assertion for detection that a permissions is assigned to the correct roles
|
// Custom assertion for detection that a permissions is assigned to the correct roles
|
||||||
should.Assertion.add('AssignedToRoles', function (roles) {
|
should.Assertion.add('AssignedToRoles', function (roles) {
|
||||||
var roleNames;
|
var roleNames;
|
||||||
@ -121,70 +124,68 @@ describe('Database Migration (special functions)', function () {
|
|||||||
permissions[29].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
permissions[29].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should populate all fixtures correctly', function (done) {
|
describe('Populate', function () {
|
||||||
var loggerStub = {
|
beforeEach(testUtils.setup());
|
||||||
info: sandbox.stub(),
|
it('should populate all fixtures correctly', function (done) {
|
||||||
warn: sandbox.stub()
|
fixtures.populate(loggerStub).then(function () {
|
||||||
};
|
var props = {
|
||||||
|
posts: Models.Post.findAll({include: ['tags']}),
|
||||||
|
tags: Models.Tag.findAll(),
|
||||||
|
users: Models.User.findAll({include: ['roles']}),
|
||||||
|
clients: Models.Client.findAll(),
|
||||||
|
roles: Models.Role.findAll(),
|
||||||
|
permissions: Models.Permission.findAll({include: ['roles']})
|
||||||
|
};
|
||||||
|
|
||||||
fixtures.populate(loggerStub).then(function () {
|
loggerStub.info.called.should.be.true();
|
||||||
var props = {
|
loggerStub.warn.called.should.be.false();
|
||||||
posts: Models.Post.findAll({include: ['tags']}),
|
|
||||||
tags: Models.Tag.findAll(),
|
|
||||||
users: Models.User.findAll({include: ['roles']}),
|
|
||||||
clients: Models.Client.findAll(),
|
|
||||||
roles: Models.Role.findAll(),
|
|
||||||
permissions: Models.Permission.findAll({include: ['roles']})
|
|
||||||
};
|
|
||||||
|
|
||||||
loggerStub.info.called.should.be.true();
|
return Promise.props(props).then(function (result) {
|
||||||
loggerStub.warn.called.should.be.false();
|
should.exist(result);
|
||||||
|
|
||||||
return Promise.props(props).then(function (result) {
|
// Post
|
||||||
should.exist(result);
|
should.exist(result.posts);
|
||||||
|
result.posts.length.should.eql(1);
|
||||||
|
result.posts.at(0).get('title').should.eql('Welcome to Ghost');
|
||||||
|
|
||||||
// Post
|
// Tag
|
||||||
should.exist(result.posts);
|
should.exist(result.tags);
|
||||||
result.posts.length.should.eql(1);
|
result.tags.length.should.eql(1);
|
||||||
result.posts.at(0).get('title').should.eql('Welcome to Ghost');
|
result.tags.at(0).get('name').should.eql('Getting Started');
|
||||||
|
|
||||||
// Tag
|
// Post Tag relation
|
||||||
should.exist(result.tags);
|
result.posts.at(0).related('tags').length.should.eql(1);
|
||||||
result.tags.length.should.eql(1);
|
result.posts.at(0).related('tags').at(0).get('name').should.eql('Getting Started');
|
||||||
result.tags.at(0).get('name').should.eql('Getting Started');
|
|
||||||
|
|
||||||
// Post Tag relation
|
// Clients
|
||||||
result.posts.at(0).related('tags').length.should.eql(1);
|
should.exist(result.clients);
|
||||||
result.posts.at(0).related('tags').at(0).get('name').should.eql('Getting Started');
|
result.clients.length.should.eql(2);
|
||||||
|
result.clients.at(0).get('name').should.eql('Ghost Admin');
|
||||||
|
result.clients.at(1).get('name').should.eql('Ghost Frontend');
|
||||||
|
|
||||||
// Clients
|
// User (Owner)
|
||||||
should.exist(result.clients);
|
should.exist(result.users);
|
||||||
result.clients.length.should.eql(2);
|
result.users.length.should.eql(1);
|
||||||
result.clients.at(0).get('name').should.eql('Ghost Admin');
|
result.users.at(0).get('name').should.eql('Ghost Owner');
|
||||||
result.clients.at(1).get('name').should.eql('Ghost Frontend');
|
result.users.at(0).related('roles').length.should.eql(1);
|
||||||
|
result.users.at(0).related('roles').at(0).get('name').should.eql('Owner');
|
||||||
|
|
||||||
// User (Owner)
|
// Roles
|
||||||
should.exist(result.users);
|
should.exist(result.roles);
|
||||||
result.users.length.should.eql(1);
|
result.roles.length.should.eql(4);
|
||||||
result.users.at(0).get('name').should.eql('Ghost Owner');
|
result.roles.at(0).get('name').should.eql('Administrator');
|
||||||
result.users.at(0).related('roles').length.should.eql(1);
|
result.roles.at(1).get('name').should.eql('Editor');
|
||||||
result.users.at(0).related('roles').at(0).get('name').should.eql('Owner');
|
result.roles.at(2).get('name').should.eql('Author');
|
||||||
|
result.roles.at(3).get('name').should.eql('Owner');
|
||||||
|
|
||||||
// Roles
|
// Permissions
|
||||||
should.exist(result.roles);
|
result.permissions.length.should.eql(30);
|
||||||
result.roles.length.should.eql(4);
|
result.permissions.toJSON().should.be.CompletePermissions();
|
||||||
result.roles.at(0).get('name').should.eql('Administrator');
|
|
||||||
result.roles.at(1).get('name').should.eql('Editor');
|
|
||||||
result.roles.at(2).get('name').should.eql('Author');
|
|
||||||
result.roles.at(3).get('name').should.eql('Owner');
|
|
||||||
|
|
||||||
// Permissions
|
done();
|
||||||
result.permissions.length.should.eql(30);
|
});
|
||||||
result.permissions.toJSON().should.be.CompletePermissions();
|
}).catch(done);
|
||||||
|
});
|
||||||
done();
|
|
||||||
});
|
|
||||||
}).catch(done);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -11,7 +11,6 @@ var should = require('should'),
|
|||||||
versioning = require('../../server/data/schema/versioning'),
|
versioning = require('../../server/data/schema/versioning'),
|
||||||
update = rewire('../../server/data/migration/fixtures/update'),
|
update = rewire('../../server/data/migration/fixtures/update'),
|
||||||
populate = rewire('../../server/data/migration/fixtures/populate'),
|
populate = rewire('../../server/data/migration/fixtures/populate'),
|
||||||
fixtureUtils = rewire('../../server/data/migration/fixtures/utils'),
|
|
||||||
fixtures004 = require('../../server/data/migration/fixtures/004'),
|
fixtures004 = require('../../server/data/migration/fixtures/004'),
|
||||||
ensureDefaultSettings = require('../../server/data/migration/fixtures/settings'),
|
ensureDefaultSettings = require('../../server/data/migration/fixtures/settings'),
|
||||||
|
|
||||||
@ -92,14 +91,13 @@ describe('Fixtures', function () {
|
|||||||
loggerStub.warn.called.should.be.false();
|
loggerStub.warn.called.should.be.false();
|
||||||
|
|
||||||
sequenceStub.calledTwice.should.be.true();
|
sequenceStub.calledTwice.should.be.true();
|
||||||
|
|
||||||
sequenceStub.firstCall.calledWith(sinon.match.array, sinon.match.object, loggerStub).should.be.true();
|
sequenceStub.firstCall.calledWith(sinon.match.array, sinon.match.object, loggerStub).should.be.true();
|
||||||
sequenceStub.secondCall.calledWith(sinon.match.array, sinon.match.object, loggerStub).should.be.true();
|
|
||||||
|
|
||||||
sequenceStub.firstCall.args[0].should.be.an.Array().with.lengthOf(1);
|
sequenceStub.firstCall.args[0].should.be.an.Array().with.lengthOf(1);
|
||||||
sequenceStub.secondCall.args[0].should.be.an.Array().with.lengthOf(8);
|
|
||||||
|
|
||||||
sequenceStub.firstCall.args[0][0].should.be.a.Function().with.property('name', 'runVersionTasks');
|
sequenceStub.firstCall.args[0][0].should.be.a.Function().with.property('name', 'runVersionTasks');
|
||||||
|
|
||||||
|
sequenceStub.secondCall.calledWith(sinon.match.array, sinon.match.object, loggerStub).should.be.true();
|
||||||
|
sequenceStub.secondCall.args[0].should.be.an.Array().with.lengthOf(8);
|
||||||
sequenceStub.secondCall.args[0][0].should.be.a.Function().with.property('name', 'moveJQuery');
|
sequenceStub.secondCall.args[0][0].should.be.a.Function().with.property('name', 'moveJQuery');
|
||||||
sequenceStub.secondCall.args[0][1].should.be.a.Function().with.property('name', 'updatePrivateSetting');
|
sequenceStub.secondCall.args[0][1].should.be.a.Function().with.property('name', 'updatePrivateSetting');
|
||||||
sequenceStub.secondCall.args[0][2].should.be.a.Function().with.property('name', 'updatePasswordSetting');
|
sequenceStub.secondCall.args[0][2].should.be.a.Function().with.property('name', 'updatePasswordSetting');
|
||||||
@ -699,26 +697,43 @@ describe('Fixtures', function () {
|
|||||||
clientAddStub = sandbox.stub(models.Client, 'add').returns(Promise.resolve()),
|
clientAddStub = sandbox.stub(models.Client, 'add').returns(Promise.resolve()),
|
||||||
permsAddStub = sandbox.stub(models.Permission, 'add').returns(Promise.resolve()),
|
permsAddStub = sandbox.stub(models.Permission, 'add').returns(Promise.resolve()),
|
||||||
|
|
||||||
|
// Existence checks
|
||||||
|
postOneStub = sandbox.stub(models.Post, 'findOne').returns(Promise.resolve()),
|
||||||
|
tagOneStub = sandbox.stub(models.Tag, 'findOne').returns(Promise.resolve()),
|
||||||
|
roleOneStub = sandbox.stub(models.Role, 'findOne').returns(Promise.resolve()),
|
||||||
|
clientOneStub = sandbox.stub(models.Client, 'findOne').returns(Promise.resolve()),
|
||||||
|
permOneStub = sandbox.stub(models.Permission, 'findOne').returns(Promise.resolve()),
|
||||||
|
|
||||||
// Relations
|
// Relations
|
||||||
modelMethodStub = {filter: sandbox.stub(), find: sandbox.stub()},
|
fromItem = {
|
||||||
|
related: sandbox.stub().returnsThis(),
|
||||||
|
findWhere: sandbox.stub().returns({})
|
||||||
|
},
|
||||||
|
toItem = [{get: sandbox.stub()}],
|
||||||
|
modelMethodStub = {filter: sandbox.stub().returns(toItem), find: sandbox.stub().returns(fromItem)},
|
||||||
permsAllStub = sandbox.stub(models.Permission, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
permsAllStub = sandbox.stub(models.Permission, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
||||||
rolesAllStub = sandbox.stub(models.Role, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
rolesAllStub = sandbox.stub(models.Role, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
||||||
postsAllStub = sandbox.stub(models.Post, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
postsAllStub = sandbox.stub(models.Post, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
||||||
tagsAllStub = sandbox.stub(models.Tag, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
tagsAllStub = sandbox.stub(models.Tag, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
||||||
|
|
||||||
// Create Owner
|
// Create Owner
|
||||||
roleOneStub = sandbox.stub(models.Role, 'findOne').returns(Promise.resolve({id: 1})),
|
|
||||||
userAddStub = sandbox.stub(models.User, 'add').returns(Promise.resolve({}));
|
userAddStub = sandbox.stub(models.User, 'add').returns(Promise.resolve({}));
|
||||||
|
roleOneStub.onCall(4).returns(Promise.resolve({id: 1}));
|
||||||
|
|
||||||
populate(loggerStub).then(function () {
|
populate(loggerStub).then(function () {
|
||||||
loggerStub.info.calledTwice.should.be.true();
|
loggerStub.info.calledTwice.should.be.true();
|
||||||
loggerStub.warn.called.should.be.false();
|
loggerStub.warn.called.should.be.false();
|
||||||
|
|
||||||
|
postOneStub.calledOnce.should.be.true();
|
||||||
postAddStub.calledOnce.should.be.true();
|
postAddStub.calledOnce.should.be.true();
|
||||||
|
tagOneStub.calledOnce.should.be.true();
|
||||||
tagAddStub.calledOnce.should.be.true();
|
tagAddStub.calledOnce.should.be.true();
|
||||||
|
roleOneStub.callCount.should.be.aboveOrEqual(4);
|
||||||
roleAddStub.callCount.should.eql(4);
|
roleAddStub.callCount.should.eql(4);
|
||||||
|
clientOneStub.calledTwice.should.be.true();
|
||||||
clientAddStub.calledTwice.should.be.true();
|
clientAddStub.calledTwice.should.be.true();
|
||||||
|
|
||||||
|
permOneStub.callCount.should.eql(30);
|
||||||
permsAddStub.called.should.be.true();
|
permsAddStub.called.should.be.true();
|
||||||
permsAddStub.callCount.should.eql(30);
|
permsAddStub.callCount.should.eql(30);
|
||||||
|
|
||||||
@ -736,53 +751,13 @@ describe('Fixtures', function () {
|
|||||||
modelMethodStub.find.callCount.should.eql(3 + 1);
|
modelMethodStub.find.callCount.should.eql(3 + 1);
|
||||||
|
|
||||||
// Create Owner
|
// Create Owner
|
||||||
roleOneStub.calledOnce.should.be.true();
|
roleOneStub.callCount.should.eql(5);
|
||||||
userAddStub.calledOnce.should.be.true();
|
userAddStub.calledOnce.should.be.true();
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Add All Relations', function () {
|
|
||||||
it('should call attach if relation models are found', function (done) {
|
|
||||||
var addAllRelations = populate.__get__('addAllRelations'),
|
|
||||||
emptyMethodStub = {filter: sandbox.stub(), find: sandbox.stub()},
|
|
||||||
// Setup a chain of methods
|
|
||||||
dataMethodStub = {
|
|
||||||
filter: sandbox.stub().returnsThis(),
|
|
||||||
find: sandbox.stub().returnsThis(),
|
|
||||||
tags: sandbox.stub().returnsThis(),
|
|
||||||
attach: sandbox.stub().returns(Promise.resolve())
|
|
||||||
},
|
|
||||||
permsAllStub = sandbox.stub(models.Permission, 'findAll').returns(Promise.resolve(emptyMethodStub)),
|
|
||||||
rolesAllStub = sandbox.stub(models.Role, 'findAll').returns(Promise.resolve(emptyMethodStub)),
|
|
||||||
postsAllStub = sandbox.stub(models.Post, 'findAll').returns(Promise.resolve(dataMethodStub)),
|
|
||||||
tagsAllStub = sandbox.stub(models.Tag, 'findAll').returns(Promise.resolve(dataMethodStub));
|
|
||||||
|
|
||||||
addAllRelations().then(function () {
|
|
||||||
permsAllStub.calledOnce.should.be.true();
|
|
||||||
rolesAllStub.calledOnce.should.be.true();
|
|
||||||
postsAllStub.calledOnce.should.be.true();
|
|
||||||
tagsAllStub.calledOnce.should.be.true();
|
|
||||||
|
|
||||||
// Permissions & Roles
|
|
||||||
emptyMethodStub.filter.called.should.be.true();
|
|
||||||
emptyMethodStub.filter.callCount.should.eql(22);
|
|
||||||
emptyMethodStub.find.called.should.be.true();
|
|
||||||
emptyMethodStub.find.callCount.should.eql(3);
|
|
||||||
|
|
||||||
// Posts & Tags
|
|
||||||
dataMethodStub.filter.calledOnce.should.be.true();
|
|
||||||
dataMethodStub.find.calledOnce.should.be.true();
|
|
||||||
dataMethodStub.tags.calledOnce.should.be.true();
|
|
||||||
dataMethodStub.attach.calledOnce.should.be.true();
|
|
||||||
dataMethodStub.attach.calledWith(dataMethodStub).should.be.true();
|
|
||||||
|
|
||||||
done();
|
|
||||||
}).catch(done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Create Owner', function () {
|
describe('Create Owner', function () {
|
||||||
var createOwner = populate.__get__('createOwner'),
|
var createOwner = populate.__get__('createOwner'),
|
||||||
roleOneStub, userAddStub;
|
roleOneStub, userAddStub;
|
||||||
@ -818,78 +793,6 @@ describe('Fixtures', function () {
|
|||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Match Func', function () {
|
|
||||||
var matchFunc = fixtureUtils.__get__('matchFunc'),
|
|
||||||
getStub;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
getStub = sandbox.stub();
|
|
||||||
getStub.withArgs('foo').returns('bar');
|
|
||||||
getStub.withArgs('fun').returns('baz');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should match undefined with no args', function () {
|
|
||||||
matchFunc()({get: getStub}).should.be.true();
|
|
||||||
getStub.calledOnce.should.be.true();
|
|
||||||
getStub.calledWith(undefined).should.be.true();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should match key with match string', function () {
|
|
||||||
matchFunc('foo', 'bar')({get: getStub}).should.be.true();
|
|
||||||
getStub.calledOnce.should.be.true();
|
|
||||||
getStub.calledWith('foo').should.be.true();
|
|
||||||
|
|
||||||
matchFunc('foo', 'buz')({get: getStub}).should.be.false();
|
|
||||||
getStub.calledTwice.should.be.true();
|
|
||||||
getStub.secondCall.calledWith('foo').should.be.true();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should match value when key is 0', function () {
|
|
||||||
matchFunc('foo', 0, 'bar')({get: getStub}).should.be.true();
|
|
||||||
getStub.calledOnce.should.be.true();
|
|
||||||
getStub.calledWith('foo').should.be.true();
|
|
||||||
|
|
||||||
matchFunc('foo', 0, 'buz')({get: getStub}).should.be.false();
|
|
||||||
getStub.calledTwice.should.be.true();
|
|
||||||
getStub.secondCall.calledWith('foo').should.be.true();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should match key & value when match is array', function () {
|
|
||||||
matchFunc(['foo', 'fun'], 'bar', 'baz')({get: getStub}).should.be.true();
|
|
||||||
getStub.calledTwice.should.be.true();
|
|
||||||
getStub.getCall(0).calledWith('fun').should.be.true();
|
|
||||||
getStub.getCall(1).calledWith('foo').should.be.true();
|
|
||||||
|
|
||||||
matchFunc(['foo', 'fun'], 'baz', 'bar')({get: getStub}).should.be.false();
|
|
||||||
getStub.callCount.should.eql(4);
|
|
||||||
getStub.getCall(2).calledWith('fun').should.be.true();
|
|
||||||
getStub.getCall(3).calledWith('foo').should.be.true();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should match key only when match is array, but value is all', function () {
|
|
||||||
matchFunc(['foo', 'fun'], 'bar', 'all')({get: getStub}).should.be.true();
|
|
||||||
getStub.calledOnce.should.be.true();
|
|
||||||
getStub.calledWith('foo').should.be.true();
|
|
||||||
|
|
||||||
matchFunc(['foo', 'fun'], 'all', 'bar')({get: getStub}).should.be.false();
|
|
||||||
getStub.callCount.should.eql(3);
|
|
||||||
getStub.getCall(1).calledWith('fun').should.be.true();
|
|
||||||
getStub.getCall(2).calledWith('foo').should.be.true();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should match key & value when match and value are arrays', function () {
|
|
||||||
matchFunc(['foo', 'fun'], 'bar', ['baz', 'buz'])({get: getStub}).should.be.true();
|
|
||||||
getStub.calledTwice.should.be.true();
|
|
||||||
getStub.getCall(0).calledWith('fun').should.be.true();
|
|
||||||
getStub.getCall(1).calledWith('foo').should.be.true();
|
|
||||||
|
|
||||||
matchFunc(['foo', 'fun'], 'bar', ['biz', 'buz'])({get: getStub}).should.be.false();
|
|
||||||
getStub.callCount.should.eql(4);
|
|
||||||
getStub.getCall(2).calledWith('fun').should.be.true();
|
|
||||||
getStub.getCall(3).calledWith('foo').should.be.true();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Ensure default settings', function () {
|
describe('Ensure default settings', function () {
|
||||||
@ -904,40 +807,4 @@ describe('Fixtures', function () {
|
|||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Utils', function () {
|
|
||||||
describe('findModelFixtureEntry', function () {
|
|
||||||
it('should fetch a single fixture entry', function () {
|
|
||||||
var foundFixture = fixtureUtils.findModelFixtureEntry('Client', {slug: 'ghost-admin'});
|
|
||||||
foundFixture.should.be.an.Object();
|
|
||||||
foundFixture.should.eql({
|
|
||||||
name: 'Ghost Admin',
|
|
||||||
slug: 'ghost-admin',
|
|
||||||
status: 'enabled'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('findPermissionModelForObject', function () {
|
|
||||||
it('should fetch a fixture with multiple entries', function () {
|
|
||||||
var foundFixture = fixtureUtils.findPermissionModelForObject('Permission', {object_type: 'db'});
|
|
||||||
foundFixture.should.be.an.Object();
|
|
||||||
foundFixture.entries.should.be.an.Array().with.lengthOf(3);
|
|
||||||
foundFixture.entries[0].should.eql({
|
|
||||||
name: 'Export database',
|
|
||||||
action_type: 'exportContent',
|
|
||||||
object_type: 'db'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('findPermissionRelationsForObject', function () {
|
|
||||||
it('should fetch a fixture with multiple entries', function () {
|
|
||||||
var foundFixture = fixtureUtils.findPermissionRelationsForObject('db');
|
|
||||||
foundFixture.should.be.an.Object();
|
|
||||||
foundFixture.entries.should.be.an.Object();
|
|
||||||
foundFixture.entries.should.have.property('Administrator', {db: 'all'});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
289
core/test/unit/migration_fixture_utils_spec.js
Normal file
289
core/test/unit/migration_fixture_utils_spec.js
Normal file
@ -0,0 +1,289 @@
|
|||||||
|
/*global describe, it, beforeEach, afterEach */
|
||||||
|
var should = require('should'),
|
||||||
|
sinon = require('sinon'),
|
||||||
|
Promise = require('bluebird'),
|
||||||
|
rewire = require('rewire'),
|
||||||
|
|
||||||
|
models = require('../../server/models'),
|
||||||
|
|
||||||
|
fixtureUtils = rewire('../../server/data/migration/fixtures/utils'),
|
||||||
|
fixtures = require('../../server/data/migration/fixtures/fixtures'),
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
|
|
||||||
|
describe('Utils', function () {
|
||||||
|
var loggerStub;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
loggerStub = {
|
||||||
|
info: sandbox.stub(),
|
||||||
|
warn: sandbox.stub()
|
||||||
|
};
|
||||||
|
|
||||||
|
models.init();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Match Func', function () {
|
||||||
|
var matchFunc = fixtureUtils.__get__('matchFunc'),
|
||||||
|
getStub;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
getStub = sandbox.stub();
|
||||||
|
getStub.withArgs('foo').returns('bar');
|
||||||
|
getStub.withArgs('fun').returns('baz');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should match undefined with no args', function () {
|
||||||
|
matchFunc()({get: getStub}).should.be.true();
|
||||||
|
getStub.calledOnce.should.be.true();
|
||||||
|
getStub.calledWith(undefined).should.be.true();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should match key with match string', function () {
|
||||||
|
matchFunc('foo', 'bar')({get: getStub}).should.be.true();
|
||||||
|
getStub.calledOnce.should.be.true();
|
||||||
|
getStub.calledWith('foo').should.be.true();
|
||||||
|
|
||||||
|
matchFunc('foo', 'buz')({get: getStub}).should.be.false();
|
||||||
|
getStub.calledTwice.should.be.true();
|
||||||
|
getStub.secondCall.calledWith('foo').should.be.true();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should match value when key is 0', function () {
|
||||||
|
matchFunc('foo', 0, 'bar')({get: getStub}).should.be.true();
|
||||||
|
getStub.calledOnce.should.be.true();
|
||||||
|
getStub.calledWith('foo').should.be.true();
|
||||||
|
|
||||||
|
matchFunc('foo', 0, 'buz')({get: getStub}).should.be.false();
|
||||||
|
getStub.calledTwice.should.be.true();
|
||||||
|
getStub.secondCall.calledWith('foo').should.be.true();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should match key & value when match is array', function () {
|
||||||
|
matchFunc(['foo', 'fun'], 'bar', 'baz')({get: getStub}).should.be.true();
|
||||||
|
getStub.calledTwice.should.be.true();
|
||||||
|
getStub.getCall(0).calledWith('fun').should.be.true();
|
||||||
|
getStub.getCall(1).calledWith('foo').should.be.true();
|
||||||
|
|
||||||
|
matchFunc(['foo', 'fun'], 'baz', 'bar')({get: getStub}).should.be.false();
|
||||||
|
getStub.callCount.should.eql(4);
|
||||||
|
getStub.getCall(2).calledWith('fun').should.be.true();
|
||||||
|
getStub.getCall(3).calledWith('foo').should.be.true();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should match key only when match is array, but value is all', function () {
|
||||||
|
matchFunc(['foo', 'fun'], 'bar', 'all')({get: getStub}).should.be.true();
|
||||||
|
getStub.calledOnce.should.be.true();
|
||||||
|
getStub.calledWith('foo').should.be.true();
|
||||||
|
|
||||||
|
matchFunc(['foo', 'fun'], 'all', 'bar')({get: getStub}).should.be.false();
|
||||||
|
getStub.callCount.should.eql(3);
|
||||||
|
getStub.getCall(1).calledWith('fun').should.be.true();
|
||||||
|
getStub.getCall(2).calledWith('foo').should.be.true();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should match key & value when match and value are arrays', function () {
|
||||||
|
matchFunc(['foo', 'fun'], 'bar', ['baz', 'buz'])({get: getStub}).should.be.true();
|
||||||
|
getStub.calledTwice.should.be.true();
|
||||||
|
getStub.getCall(0).calledWith('fun').should.be.true();
|
||||||
|
getStub.getCall(1).calledWith('foo').should.be.true();
|
||||||
|
|
||||||
|
matchFunc(['foo', 'fun'], 'bar', ['biz', 'buz'])({get: getStub}).should.be.false();
|
||||||
|
getStub.callCount.should.eql(4);
|
||||||
|
getStub.getCall(2).calledWith('fun').should.be.true();
|
||||||
|
getStub.getCall(3).calledWith('foo').should.be.true();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Add Fixtures For Model', function () {
|
||||||
|
it('should call add for main post fixture', function (done) {
|
||||||
|
var postOneStub = sandbox.stub(models.Post, 'findOne').returns(Promise.resolve()),
|
||||||
|
postAddStub = sandbox.stub(models.Post, 'add').returns(Promise.resolve({}));
|
||||||
|
|
||||||
|
fixtureUtils.addFixturesForModel(fixtures.models[0]).then(function (result) {
|
||||||
|
should.exist(result);
|
||||||
|
result.should.be.an.Object();
|
||||||
|
result.should.have.property('expected', 1);
|
||||||
|
result.should.have.property('done', 1);
|
||||||
|
|
||||||
|
postOneStub.calledOnce.should.be.true();
|
||||||
|
postAddStub.calledOnce.should.be.true();
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not call add for main post fixture if it is already found', function (done) {
|
||||||
|
var postOneStub = sandbox.stub(models.Post, 'findOne').returns(Promise.resolve({})),
|
||||||
|
postAddStub = sandbox.stub(models.Post, 'add').returns(Promise.resolve({}));
|
||||||
|
fixtureUtils.addFixturesForModel(fixtures.models[0]).then(function (result) {
|
||||||
|
should.exist(result);
|
||||||
|
result.should.be.an.Object();
|
||||||
|
result.should.have.property('expected', 1);
|
||||||
|
result.should.have.property('done', 0);
|
||||||
|
|
||||||
|
postOneStub.calledOnce.should.be.true();
|
||||||
|
postAddStub.calledOnce.should.be.false();
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Add Fixtures For Relation', function () {
|
||||||
|
it('should call attach for permissions-roles', function (done) {
|
||||||
|
var fromItem = {
|
||||||
|
related: sandbox.stub().returnsThis(),
|
||||||
|
findWhere: sandbox.stub().returns(),
|
||||||
|
permissions: sandbox.stub().returnsThis(),
|
||||||
|
attach: sandbox.stub().returns(Promise.resolve([{}]))
|
||||||
|
},
|
||||||
|
toItem = [{get: sandbox.stub()}],
|
||||||
|
dataMethodStub = {
|
||||||
|
filter: sandbox.stub().returns(toItem),
|
||||||
|
find: sandbox.stub().returns(fromItem)
|
||||||
|
},
|
||||||
|
permsAllStub = sandbox.stub(models.Permission, 'findAll').returns(Promise.resolve(dataMethodStub)),
|
||||||
|
rolesAllStub = sandbox.stub(models.Role, 'findAll').returns(Promise.resolve(dataMethodStub));
|
||||||
|
|
||||||
|
fixtureUtils.addFixturesForRelation(fixtures.relations[0]).then(function (result) {
|
||||||
|
should.exist(result);
|
||||||
|
result.should.be.an.Object();
|
||||||
|
result.should.have.property('expected', 22);
|
||||||
|
result.should.have.property('done', 22);
|
||||||
|
|
||||||
|
// Permissions & Roles
|
||||||
|
permsAllStub.calledOnce.should.be.true();
|
||||||
|
rolesAllStub.calledOnce.should.be.true();
|
||||||
|
dataMethodStub.filter.callCount.should.eql(22);
|
||||||
|
dataMethodStub.find.callCount.should.eql(3);
|
||||||
|
|
||||||
|
fromItem.related.callCount.should.eql(22);
|
||||||
|
fromItem.findWhere.callCount.should.eql(22);
|
||||||
|
toItem[0].get.callCount.should.eql(44);
|
||||||
|
|
||||||
|
fromItem.permissions.callCount.should.eql(22);
|
||||||
|
fromItem.attach.callCount.should.eql(22);
|
||||||
|
fromItem.attach.calledWith(toItem).should.be.true();
|
||||||
|
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call attach for posts-tags', function (done) {
|
||||||
|
var fromItem = {
|
||||||
|
related: sandbox.stub().returnsThis(),
|
||||||
|
findWhere: sandbox.stub().returns(),
|
||||||
|
tags: sandbox.stub().returnsThis(),
|
||||||
|
attach: sandbox.stub().returns(Promise.resolve([{}]))
|
||||||
|
},
|
||||||
|
toItem = [{get: sandbox.stub()}],
|
||||||
|
dataMethodStub = {
|
||||||
|
filter: sandbox.stub().returns(toItem),
|
||||||
|
find: sandbox.stub().returns(fromItem)
|
||||||
|
},
|
||||||
|
|
||||||
|
postsAllStub = sandbox.stub(models.Post, 'findAll').returns(Promise.resolve(dataMethodStub)),
|
||||||
|
tagsAllStub = sandbox.stub(models.Tag, 'findAll').returns(Promise.resolve(dataMethodStub));
|
||||||
|
|
||||||
|
fixtureUtils.addFixturesForRelation(fixtures.relations[1]).then(function (result) {
|
||||||
|
should.exist(result);
|
||||||
|
result.should.be.an.Object();
|
||||||
|
result.should.have.property('expected', 1);
|
||||||
|
result.should.have.property('done', 1);
|
||||||
|
|
||||||
|
// Posts & Tags
|
||||||
|
postsAllStub.calledOnce.should.be.true();
|
||||||
|
tagsAllStub.calledOnce.should.be.true();
|
||||||
|
dataMethodStub.filter.calledOnce.should.be.true();
|
||||||
|
dataMethodStub.find.calledOnce.should.be.true();
|
||||||
|
|
||||||
|
fromItem.related.calledOnce.should.be.true();
|
||||||
|
fromItem.findWhere.calledOnce.should.be.true();
|
||||||
|
toItem[0].get.calledOnce.should.be.true();
|
||||||
|
|
||||||
|
fromItem.tags.calledOnce.should.be.true();
|
||||||
|
fromItem.attach.calledOnce.should.be.true();
|
||||||
|
fromItem.attach.calledWith(toItem).should.be.true();
|
||||||
|
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will not call attach for posts-tags if already present', function (done) {
|
||||||
|
var fromItem = {
|
||||||
|
related: sandbox.stub().returnsThis(),
|
||||||
|
findWhere: sandbox.stub().returns({}),
|
||||||
|
tags: sandbox.stub().returnsThis(),
|
||||||
|
attach: sandbox.stub().returns(Promise.resolve({}))
|
||||||
|
},
|
||||||
|
toItem = [{get: sandbox.stub()}],
|
||||||
|
dataMethodStub = {
|
||||||
|
filter: sandbox.stub().returns(toItem),
|
||||||
|
find: sandbox.stub().returns(fromItem)
|
||||||
|
},
|
||||||
|
|
||||||
|
postsAllStub = sandbox.stub(models.Post, 'findAll').returns(Promise.resolve(dataMethodStub)),
|
||||||
|
tagsAllStub = sandbox.stub(models.Tag, 'findAll').returns(Promise.resolve(dataMethodStub));
|
||||||
|
|
||||||
|
fixtureUtils.addFixturesForRelation(fixtures.relations[1]).then(function (result) {
|
||||||
|
should.exist(result);
|
||||||
|
result.should.be.an.Object();
|
||||||
|
result.should.have.property('expected', 1);
|
||||||
|
result.should.have.property('done', 0);
|
||||||
|
|
||||||
|
// Posts & Tags
|
||||||
|
postsAllStub.calledOnce.should.be.true();
|
||||||
|
tagsAllStub.calledOnce.should.be.true();
|
||||||
|
dataMethodStub.filter.calledOnce.should.be.true();
|
||||||
|
dataMethodStub.find.calledOnce.should.be.true();
|
||||||
|
|
||||||
|
fromItem.related.calledOnce.should.be.true();
|
||||||
|
fromItem.findWhere.calledOnce.should.be.true();
|
||||||
|
toItem[0].get.calledOnce.should.be.true();
|
||||||
|
|
||||||
|
fromItem.tags.called.should.be.false();
|
||||||
|
fromItem.attach.called.should.be.false();
|
||||||
|
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('findModelFixtureEntry', function () {
|
||||||
|
it('should fetch a single fixture entry', function () {
|
||||||
|
var foundFixture = fixtureUtils.findModelFixtureEntry('Client', {slug: 'ghost-admin'});
|
||||||
|
foundFixture.should.be.an.Object();
|
||||||
|
foundFixture.should.eql({
|
||||||
|
name: 'Ghost Admin',
|
||||||
|
slug: 'ghost-admin',
|
||||||
|
status: 'enabled'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('findModelFixtures', function () {
|
||||||
|
it('should fetch a fixture with multiple entries', function () {
|
||||||
|
var foundFixture = fixtureUtils.findModelFixtures('Permission', {object_type: 'db'});
|
||||||
|
foundFixture.should.be.an.Object();
|
||||||
|
foundFixture.entries.should.be.an.Array().with.lengthOf(3);
|
||||||
|
foundFixture.entries[0].should.eql({
|
||||||
|
name: 'Export database',
|
||||||
|
action_type: 'exportContent',
|
||||||
|
object_type: 'db'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('findPermissionRelationsForObject', function () {
|
||||||
|
it('should fetch a fixture with multiple entries', function () {
|
||||||
|
var foundFixture = fixtureUtils.findPermissionRelationsForObject('db');
|
||||||
|
foundFixture.should.be.an.Object();
|
||||||
|
foundFixture.entries.should.be.an.Object();
|
||||||
|
foundFixture.entries.should.have.property('Administrator', {db: 'all'});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -316,7 +316,7 @@ fixtures = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
permissionsFor: function permissionsFor(obj) {
|
permissionsFor: function permissionsFor(obj) {
|
||||||
var permsToInsert = fixtureUtils.findPermissionModelForObject('Permission', {object_type: obj}).entries,
|
var permsToInsert = fixtureUtils.findModelFixtures('Permission', {object_type: obj}).entries,
|
||||||
permsRolesToInsert = fixtureUtils.findPermissionRelationsForObject(obj).entries,
|
permsRolesToInsert = fixtureUtils.findPermissionRelationsForObject(obj).entries,
|
||||||
actions = [],
|
actions = [],
|
||||||
permissionsRoles = [],
|
permissionsRoles = [],
|
||||||
|
Loading…
Reference in New Issue
Block a user