0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-18 02:21:47 -05:00

Merge pull request #6654 from ErisDS/fixture-population

Improve fixture population code
This commit is contained in:
Jason Williams 2016-04-02 09:04:24 -05:00
commit 5f8ef26eb3
9 changed files with 476 additions and 311 deletions

View file

@ -3,7 +3,7 @@ var models = require('../../../../models'),
_ = require('lodash'),
crypto = require('crypto'),
adminClient = require('../fixtures').models.Client[0],
adminClient = require('../utils').findModelFixtureEntry('Client', {slug: 'ghost-admin'}),
message = 'Update ghost-admin client fixture';
module.exports = function updateGhostAdminClient(options, logger) {

View file

@ -1,7 +1,7 @@
// Create a new `ghost-frontend` client for use in themes
var models = require('../../../../models'),
frontendClient = require('../fixtures').models.Client[1],
frontendClient = require('../utils').findModelFixtureEntry('Client', {slug: 'ghost-frontend'}),
message = 'Add ghost-frontend client fixture';
module.exports = function addGhostFrontendClient(options, logger) {

View file

@ -1,44 +1,53 @@
{
"models": {
"Post": [
{
"title": "Welcome to Ghost",
"slug": "welcome-to-ghost",
"markdown": "You're live! Nice. We've put together a little post to introduce you to the Ghost editor and get you started. You can manage your content by signing in to the admin area at `<your blog URL>/ghost/`. When you arrive, you can select this post from a list on the left and see a preview of it on the right. Click the little pencil icon at the top of the preview to edit this post and read the next section!\n\n## Getting Started\n\nGhost uses something called Markdown for writing. Essentially, it's a shorthand way to manage your post formatting as you write!\n\nWriting in Markdown is really easy. In the left hand panel of Ghost, you simply write as you normally would. Where appropriate, you can use *shortcuts* to **style** your content. For example, a list:\n\n* Item number one\n* Item number two\n * A nested item\n* A final item\n\nor with numbers!\n\n1. Remember to buy some milk\n2. Drink the milk\n3. Tweet that I remembered to buy the milk, and drank it\n\n### Links\n\nWant to link to a source? No problem. If you paste in a URL, like http://ghost.org - it'll automatically be linked up. But if you want to customise your anchor text, you can do that too! Here's a link to [the Ghost website](http://ghost.org). Neat.\n\n### What about Images?\n\nImages work too! Already know the URL of the image you want to include in your article? Simply paste it in like this to make it show up:\n\n![The Ghost Logo](https://ghost.org/images/ghost.png)\n\nNot sure which image you want to use yet? That's ok too. Leave yourself a descriptive placeholder and keep writing. Come back later and drag and drop the image in to upload:\n\n![A bowl of bananas]\n\n\n### Quoting\n\nSometimes a link isn't enough, you want to quote someone on what they've said. Perhaps you've started using a new blogging platform and feel the sudden urge to share their slogan? A quote might be just the way to do it!\n\n> Ghost - Just a blogging platform\n\n### Working with Code\n\nGot a streak of geek? We've got you covered there, too. You can write inline `<code>` blocks really easily with back ticks. Want to show off something more comprehensive? 4 spaces of indentation gets you there.\n\n .awesome-thing {\n display: block;\n width: 100%;\n }\n\n### Ready for a Break? \n\nThrow 3 or more dashes down on any new line and you've got yourself a fancy new divider. Aw yeah.\n\n---\n\n### Advanced Usage\n\nThere's one fantastic secret about Markdown. If you want, you can write plain old HTML and it'll still work! Very flexible.\n\n<input type=\"text\" placeholder=\"I'm an input field!\" />\n\nThat should be enough to get you started. Have fun - and let us know what you think :)",
"image": null,
"featured": false,
"page": false,
"status": "published",
"language": "en_US",
"meta_title": null,
"meta_description": null
}
],
"Tag": [
{
"name": "Getting Started",
"slug": "getting-started",
"description": null,
"parent_id": null,
"meta_title": null,
"meta_description": null
}
],
"Client": [
{
"name": "Ghost Admin",
"slug": "ghost-admin",
"status": "enabled"
},
{
"name": "Ghost Frontend",
"slug": "ghost-frontend",
"status": "enabled"
}
],
"Role": [
"models": [
{
"name": "Post",
"entries": [
{
"title": "Welcome to Ghost",
"slug": "welcome-to-ghost",
"markdown": "You're live! Nice. We've put together a little post to introduce you to the Ghost editor and get you started. You can manage your content by signing in to the admin area at `<your blog URL>/ghost/`. When you arrive, you can select this post from a list on the left and see a preview of it on the right. Click the little pencil icon at the top of the preview to edit this post and read the next section!\n\n## Getting Started\n\nGhost uses something called Markdown for writing. Essentially, it's a shorthand way to manage your post formatting as you write!\n\nWriting in Markdown is really easy. In the left hand panel of Ghost, you simply write as you normally would. Where appropriate, you can use *shortcuts* to **style** your content. For example, a list:\n\n* Item number one\n* Item number two\n * A nested item\n* A final item\n\nor with numbers!\n\n1. Remember to buy some milk\n2. Drink the milk\n3. Tweet that I remembered to buy the milk, and drank it\n\n### Links\n\nWant to link to a source? No problem. If you paste in a URL, like http://ghost.org - it'll automatically be linked up. But if you want to customise your anchor text, you can do that too! Here's a link to [the Ghost website](http://ghost.org). Neat.\n\n### What about Images?\n\nImages work too! Already know the URL of the image you want to include in your article? Simply paste it in like this to make it show up:\n\n![The Ghost Logo](https://ghost.org/images/ghost.png)\n\nNot sure which image you want to use yet? That's ok too. Leave yourself a descriptive placeholder and keep writing. Come back later and drag and drop the image in to upload:\n\n![A bowl of bananas]\n\n\n### Quoting\n\nSometimes a link isn't enough, you want to quote someone on what they've said. Perhaps you've started using a new blogging platform and feel the sudden urge to share their slogan? A quote might be just the way to do it!\n\n> Ghost - Just a blogging platform\n\n### Working with Code\n\nGot a streak of geek? We've got you covered there, too. You can write inline `<code>` blocks really easily with back ticks. Want to show off something more comprehensive? 4 spaces of indentation gets you there.\n\n .awesome-thing {\n display: block;\n width: 100%;\n }\n\n### Ready for a Break? \n\nThrow 3 or more dashes down on any new line and you've got yourself a fancy new divider. Aw yeah.\n\n---\n\n### Advanced Usage\n\nThere's one fantastic secret about Markdown. If you want, you can write plain old HTML and it'll still work! Very flexible.\n\n<input type=\"text\" placeholder=\"I'm an input field!\" />\n\nThat should be enough to get you started. Have fun - and let us know what you think :)",
"image": null,
"featured": false,
"page": false,
"status": "published",
"language": "en_US",
"meta_title": null,
"meta_description": null
}
]
},
{
"name": "Tag",
"entries": [
{
"name": "Getting Started",
"slug": "getting-started",
"description": null,
"parent_id": null,
"meta_title": null,
"meta_description": null
}
]
},
{
"name": "Client",
"entries": [
{
"name": "Ghost Admin",
"slug": "ghost-admin",
"status": "enabled"
},
{
"name": "Ghost Frontend",
"slug": "ghost-frontend",
"status": "enabled"
}
]
},
{
"name": "Role",
"entries": [
{
"name": "Administrator",
"description": "Administrators"
@ -51,164 +60,169 @@
"name": "Author",
"description": "Authors"
},
{
"name": "Owner",
"description": "Blog Owner"
}
],
"Permission": [
{
"name": "Export database",
"action_type": "exportContent",
"object_type": "db"
},
{
"name": "Import database",
"action_type": "importContent",
"object_type": "db"
},
{
"name": "Delete all content",
"action_type": "deleteAllContent",
"object_type": "db"
},
{
"name": "Send mail",
"action_type": "send",
"object_type": "mail"
},
{
"name": "Browse notifications",
"action_type": "browse",
"object_type": "notification"
},
{
"name": "Add notifications",
"action_type": "add",
"object_type": "notification"
},
{
"name": "Delete notifications",
"action_type": "destroy",
"object_type": "notification"
},
{
"name": "Browse posts",
"action_type": "browse",
"object_type": "post"
},
{
"name": "Read posts",
"action_type": "read",
"object_type": "post"
},
{
"name": "Edit posts",
"action_type": "edit",
"object_type": "post"
},
{
"name": "Add posts",
"action_type": "add",
"object_type": "post"
},
{
"name": "Delete posts",
"action_type": "destroy",
"object_type": "post"
},
{
"name": "Browse settings",
"action_type": "browse",
"object_type": "setting"
},
{
"name": "Read settings",
"action_type": "read",
"object_type": "setting"
},
{
"name": "Edit settings",
"action_type": "edit",
"object_type": "setting"
},
{
"name": "Generate slugs",
"action_type": "generate",
"object_type": "slug"
},
{
"name": "Browse tags",
"action_type": "browse",
"object_type": "tag"
},
{
"name": "Read tags",
"action_type": "read",
"object_type": "tag"
},
{
"name": "Edit tags",
"action_type": "edit",
"object_type": "tag"
},
{
"name": "Add tags",
"action_type": "add",
"object_type": "tag"
},
{
"name": "Delete tags",
"action_type": "destroy",
"object_type": "tag"
},
{
"name": "Browse themes",
"action_type": "browse",
"object_type": "theme"
},
{
"name": "Edit themes",
"action_type": "edit",
"object_type": "theme"
},
{
"name": "Browse users",
"action_type": "browse",
"object_type": "user"
},
{
"name": "Read users",
"action_type": "read",
"object_type": "user"
},
{
"name": "Edit users",
"action_type": "edit",
"object_type": "user"
},
{
"name": "Add users",
"action_type": "add",
"object_type": "user"
},
{
"name": "Delete users",
"action_type": "destroy",
"object_type": "user"
},
{
"name": "Assign a role",
"action_type": "assign",
"object_type": "role"
},
{
"name": "Browse roles",
"action_type": "browse",
"object_type": "role"
}
]
},
{
"name": "Owner",
"description": "Blog Owner"
}
]
},
{
"name": "Permission",
"entries": [
{
"name": "Export database",
"action_type": "exportContent",
"object_type": "db"
},
{
"name": "Import database",
"action_type": "importContent",
"object_type": "db"
},
{
"name": "Delete all content",
"action_type": "deleteAllContent",
"object_type": "db"
},
{
"name": "Send mail",
"action_type": "send",
"object_type": "mail"
},
{
"name": "Browse notifications",
"action_type": "browse",
"object_type": "notification"
},
{
"name": "Add notifications",
"action_type": "add",
"object_type": "notification"
},
{
"name": "Delete notifications",
"action_type": "destroy",
"object_type": "notification"
},
{
"name": "Browse posts",
"action_type": "browse",
"object_type": "post"
},
{
"name": "Read posts",
"action_type": "read",
"object_type": "post"
},
{
"name": "Edit posts",
"action_type": "edit",
"object_type": "post"
},
{
"name": "Add posts",
"action_type": "add",
"object_type": "post"
},
{
"name": "Delete posts",
"action_type": "destroy",
"object_type": "post"
},
{
"name": "Browse settings",
"action_type": "browse",
"object_type": "setting"
},
{
"name": "Read settings",
"action_type": "read",
"object_type": "setting"
},
{
"name": "Edit settings",
"action_type": "edit",
"object_type": "setting"
},
{
"name": "Generate slugs",
"action_type": "generate",
"object_type": "slug"
},
{
"name": "Browse tags",
"action_type": "browse",
"object_type": "tag"
},
{
"name": "Read tags",
"action_type": "read",
"object_type": "tag"
},
{
"name": "Edit tags",
"action_type": "edit",
"object_type": "tag"
},
{
"name": "Add tags",
"action_type": "add",
"object_type": "tag"
},
{
"name": "Delete tags",
"action_type": "destroy",
"object_type": "tag"
},
{
"name": "Browse themes",
"action_type": "browse",
"object_type": "theme"
},
{
"name": "Edit themes",
"action_type": "edit",
"object_type": "theme"
},
{
"name": "Browse users",
"action_type": "browse",
"object_type": "user"
},
{
"name": "Read users",
"action_type": "read",
"object_type": "user"
},
{
"name": "Edit users",
"action_type": "edit",
"object_type": "user"
},
{
"name": "Add users",
"action_type": "add",
"object_type": "user"
},
{
"name": "Delete users",
"action_type": "destroy",
"object_type": "user"
},
{
"name": "Assign a role",
"action_type": "assign",
"object_type": "role"
},
{
"name": "Browse roles",
"action_type": "browse",
"object_type": "role"
}
]
}
],
"relations": [
{
"from": {

View file

@ -3,20 +3,16 @@
// This is done automatically, by reading the fixtures.json file
// All models, and relationships inside the file are then setup.
var Promise = require('bluebird'),
_ = require('lodash'),
models = require('../../../models'),
utils = require('../../../utils'),
sequence = require('../../../utils/sequence'),
fixtures = require('./fixtures'),
var Promise = require('bluebird'),
models = require('../../../models'),
coreUtils = require('../../../utils'),
fixtureUtils = require('./utils'),
fixtures = require('./fixtures'),
// private
addAllModels,
addAllRelations,
fetchRelationData,
matchFunc,
createOwner,
modelOptions = {context: {internal: true}},
// public
populate;
@ -28,67 +24,7 @@ var Promise = require('bluebird'),
* @returns {Promise<*>}
*/
addAllModels = function addAllModels() {
var ops = [];
_.each(fixtures.models, function (items, modelName) {
_.each(items, function (item) {
ops.push(function () {
return models[modelName].add(item, modelOptions);
});
});
});
return sequence(ops);
};
/**
* ### Fetch Relation Data
* Before we build relations we need to fetch all of the models from both sides so that we can
* use filter and find to quickly locate the correct models.
*
* @param {Object} relation
* @returns {Promise<*>}
*/
fetchRelationData = function fetchRelationData(relation) {
var props = {
from: models[relation.from.model].findAll(modelOptions),
to: models[relation.to.model].findAll(modelOptions)
};
return Promise.props(props);
};
/**
* ### Match Func
* Figures out how to match across various combinations of keys and values.
* Match can be a string or an array containing 2 strings
* Key and Value are the values to be found
* Value can also be an array, in which case we look for a match in the array.
*
* @param {String|Array} match
* @param {String} key
* @param {String|Array} [value]
* @returns {Function}
*/
matchFunc = function matchFunc(match, key, value) {
if (_.isArray(match)) {
return function (item) {
var valueTest = true;
if (_.isArray(value)) {
valueTest = value.indexOf(item.get(match[1])) > -1;
} else if (value !== 'all') {
valueTest = item.get(match[1]) === value;
}
return item.get(match[0]) === key && valueTest;
};
}
return function (item) {
key = key === 0 && value ? value : key;
return item.get(match) === key;
};
return Promise.mapSeries(fixtures.models, fixtureUtils.addFixturesForModel);
};
/**
@ -98,26 +34,7 @@ matchFunc = function matchFunc(match, key, value) {
* @returns {Promise|Array}
*/
addAllRelations = function addAllRelations() {
return Promise.map(fixtures.relations, function (relation) {
return fetchRelationData(relation).then(function (data) {
var ops = [];
_.each(relation.entries, function (entry, key) {
var fromItem = data.from.find(matchFunc(relation.from.match, key));
_.each(entry, function (value, key) {
var toItem = data.to.filter(matchFunc(relation.to.match, key, value));
if (toItem) {
ops.push(function () {
return fromItem[relation.from.relation]().attach(toItem);
});
}
});
});
return sequence(ops);
});
});
return Promise.mapSeries(fixtures.relations, fixtureUtils.addFixturesForRelation);
};
/**
@ -133,7 +50,7 @@ createOwner = function createOwner(logger) {
name: 'Ghost Owner',
email: 'ghost@ghost.org',
status: 'inactive',
password: utils.uid(50)
password: coreUtils.uid(50)
};
return models.Role.findOne({name: 'Owner'}).then(function (ownerRole) {
@ -141,7 +58,7 @@ createOwner = function createOwner(logger) {
user.roles = [ownerRole.id];
logger.info('Creating owner');
return models.User.add(user, modelOptions);
return models.User.add(user, fixtureUtils.modelOptions);
}
});
};
@ -158,12 +75,12 @@ populate = function populate(logger) {
logger.info('Running fixture populations');
// ### Ensure all models are added
return addAllModels().then(function () {
// ### Ensure all relations are added
return addAllRelations();
}).then(function () {
return createOwner(logger);
});
return addAllModels()
// ### Ensure all relations are added
.then(addAllRelations)
.then(function () {
return createOwner(logger);
});
};
module.exports = populate;

View file

@ -3,11 +3,9 @@
// This is done manually, through a series of files stored in an adjacent folder
// E.g. if we update to version 004, all the tasks in /004/ are executed
var sequence = require('../../../utils/sequence'),
versioning = require('../../schema').versioning,
// Private
modelOptions = {context: {internal: true}},
var sequence = require('../../../utils/sequence'),
versioning = require('../../schema').versioning,
fixtureUtils = require('./utils'),
// Public
update;
@ -29,14 +27,14 @@ update = function update(versions, logger) {
if (tasks && tasks.length > 0) {
ops.push(function runVersionTasks() {
logger.info('Updating fixtures to ' + version);
return sequence(tasks, modelOptions, logger);
return sequence(tasks, fixtureUtils.modelOptions, logger);
});
}
return ops;
}, []);
return sequence(ops, modelOptions, logger);
return sequence(ops, fixtureUtils.modelOptions, logger);
};
module.exports = update;

View file

@ -0,0 +1,200 @@
// # Fixture Utils
// Standalone file which can be required to help with advanced operations on the fixtures.json file
var _ = require('lodash'),
Promise = require('bluebird'),
models = require('../../../models'),
sequence = require('../../../utils/sequence'),
fixtures = require('./fixtures'),
// Private
matchFunc,
fetchRelationData,
findRelationFixture,
findModelFixture,
// Public
modelOptions = {context: {internal: true}},
addFixturesForModel,
addFixturesForRelation,
findModelFixtureEntry,
findPermissionModelForObject,
findPermissionRelationsForObject;
/**
* ### Match Func
* Figures out how to match across various combinations of keys and values.
* Match can be a string or an array containing 2 strings
* Key and Value are the values to be found
* Value can also be an array, in which case we look for a match in the array.
* @api private
* @param {String|Array} match
* @param {String|Integer} key
* @param {String|Array} [value]
* @returns {Function} matching function
*/
matchFunc = function matchFunc(match, key, value) {
if (_.isArray(match)) {
return function (item) {
var valueTest = true;
if (_.isArray(value)) {
valueTest = value.indexOf(item.get(match[1])) > -1;
} else if (value !== 'all') {
valueTest = item.get(match[1]) === value;
}
return item.get(match[0]) === key && valueTest;
};
}
return function (item) {
key = key === 0 && value ? value : key;
return item.get(match) === key;
};
};
/**
* ### Fetch Relation Data
* Before we build relations we need to fetch all of the models from both sides so that we can
* use filter and find to quickly locate the correct models.
* @api private
* @param {{from, to, entries}} relation
* @returns {Promise<*>}
*/
fetchRelationData = function fetchRelationData(relation) {
var props = {
from: models[relation.from.model].findAll(modelOptions),
to: models[relation.to.model].findAll(modelOptions)
};
return Promise.props(props);
};
/**
* ### Add Fixtures for Model
* Takes a model fixture, with a name and some entries and processes these
* into a sequence of promises to get each fixture added.
*
* @param {{name, entries}} modelFixture
* @returns {Promise.<*>}
*/
addFixturesForModel = function addFixturesForModel(modelFixture) {
return Promise.mapSeries(modelFixture.entries, function (entry) {
return models[modelFixture.name].add(entry, modelOptions);
});
};
/**
* ## Add Fixtures for Relation
* Takes a relation fixtures object, with a from, to and some entries and processes these
* into a sequence of promises, to get each fixture added.
*
* @param {{from, to, entries}} relationFixture
* @returns {Promise.<*>}
*/
addFixturesForRelation = function addFixturesForRelation(relationFixture) {
return fetchRelationData(relationFixture).then(function getRelationOps(data) {
var ops = [];
_.each(relationFixture.entries, function processEntries(entry, key) {
var fromItem = data.from.find(matchFunc(relationFixture.from.match, key));
_.each(entry, function processEntryValues(value, key) {
var toItem = data.to.filter(matchFunc(relationFixture.to.match, key, value));
if (toItem) {
ops.push(function addRelationItem() {
return fromItem[relationFixture.from.relation]().attach(toItem);
});
}
});
});
return sequence(ops);
});
};
/**
* ### Find Model Fixture
* Finds a model fixture based on model name
* @api private
* @param {String} modelName
* @returns {Object} model fixture
*/
findModelFixture = function findModelFixture(modelName) {
return _.find(fixtures.models, function (modelFixture) {
return modelFixture.name === modelName;
});
};
/**
* ### Find Model Fixture Entry
* Find a single model fixture entry by model name & a matching expression for the FIND function
* @param {String} modelName
* @param {String|Object|Function} matchExpr
* @returns {Object} model fixture entry
*/
findModelFixtureEntry = function findModelFixtureEntry(modelName, matchExpr) {
return _.find(findModelFixture(modelName).entries, matchExpr);
};
/**
* ### Find All Model Fixture
* Find a model fixture name & a matching expression for the FILTER function
* @param {String} modelName
* @param {String|Object|Function} matchExpr
* @returns {Object} model fixture
*/
findPermissionModelForObject = function findPermissionModelForObject(modelName, matchExpr) {
var foundModel = _.cloneDeep(findModelFixture(modelName));
foundModel.entries = _.filter(foundModel.entries, matchExpr);
return foundModel;
};
/**
* ### Find Relation Fixture
* Find a relation fixture by from & to models
* @api private
* @param {String} from
* @param {String} to
* @returns {Object} relation fixture
*/
findRelationFixture = function findRelationFixture(from, to) {
return _.find(fixtures.relations, function (relation) {
return relation.from.model === from && relation.to.model === to;
});
};
/**
* ### Find Permission Relations For Object
* Specialist function can return the permission relation fixture with only entries for a particular object.model
* @param {String} objName
* @returns {Object} fixture relation
*/
findPermissionRelationsForObject = function findPermissionRelationsForObject(objName) {
// Make a copy and delete any entries we don't want
var foundRelation = _.cloneDeep(findRelationFixture('Role', 'Permission'));
_.each(foundRelation.entries, function (entry, role) {
_.each(entry, function (perm, obj) {
if (obj !== objName) {
delete entry[obj];
}
});
if (_.isEmpty(entry)) {
delete foundRelation.entries[role];
}
});
return foundRelation;
};
module.exports = {
addFixturesForModel: addFixturesForModel,
addFixturesForRelation: addFixturesForRelation,
findModelFixtureEntry: findModelFixtureEntry,
findPermissionModelForObject: findPermissionModelForObject,
findPermissionRelationsForObject: findPermissionRelationsForObject,
modelOptions: modelOptions
};

View file

@ -11,6 +11,7 @@ var should = require('should'),
versioning = require('../../server/data/schema/versioning'),
update = rewire('../../server/data/migration/fixtures/update'),
populate = rewire('../../server/data/migration/fixtures/populate'),
fixtureUtils = rewire('../../server/data/migration/fixtures/utils'),
fixtures004 = require('../../server/data/migration/fixtures/004'),
ensureDefaultSettings = require('../../server/data/migration/fixtures/settings'),
@ -819,7 +820,7 @@ describe('Fixtures', function () {
});
describe('Match Func', function () {
var matchFunc = populate.__get__('matchFunc'),
var matchFunc = fixtureUtils.__get__('matchFunc'),
getStub;
beforeEach(function () {
@ -903,4 +904,40 @@ describe('Fixtures', function () {
}).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'});
});
});
});
});

View file

@ -35,7 +35,7 @@ describe('DB version integrity', function () {
// Only these variables should need updating
var currentDbVersion = '004',
currentSchemaHash = 'a195562bf4915e3f3f610f6d178aba01',
currentFixturesHash = '17d6aa36a6ba904adca90279eb929381';
currentFixturesHash = '77ebb081539f9e0c49f487faf7fd929e';
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
// and the values above will need updating as confirmation

View file

@ -5,7 +5,7 @@ var Promise = require('bluebird'),
uuid = require('node-uuid'),
db = require('../../server/data/db'),
migration = require('../../server/data/migration/'),
mainFixtures = require('../../server/data/migration/fixtures').fixtures,
fixtureUtils = require('../../server/data/migration/fixtures/utils'),
Models = require('../../server/models'),
SettingsAPI = require('../../server/api/settings'),
permissions = require('../../server/permissions'),
@ -316,8 +316,8 @@ fixtures = {
},
permissionsFor: function permissionsFor(obj) {
var permsToInsert = _.filter(mainFixtures.models.Permission, function (perm) { return perm.object_type === obj; }),
permsRolesToInsert = mainFixtures.relations[0].entries,
var permsToInsert = fixtureUtils.findPermissionModelForObject('Permission', {object_type: obj}).entries,
permsRolesToInsert = fixtureUtils.findPermissionRelationsForObject(obj).entries,
actions = [],
permissionsRoles = [],
roles = {
@ -328,7 +328,6 @@ fixtures = {
};
permsToInsert = _.map(permsToInsert, function (perms) {
perms.object_type = obj;
actions.push(perms.action_type);
return DataGenerator.forKnex.createBasic(perms);
});