mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Moved published_at
creation to fixtures/utils (#8595)
no issue - follow-up from #8573 - bove the hack that creates published_at values from the migration fn to our fixture util
This commit is contained in:
parent
4ac34a7f33
commit
0ce24b48bd
2 changed files with 23 additions and 16 deletions
|
@ -1,8 +1,7 @@
|
|||
var Promise = require('bluebird'),
|
||||
_ = require('lodash'),
|
||||
fixtures = require('../../schema/fixtures'),
|
||||
logging = require('../../../logging'),
|
||||
moment = require('moment');
|
||||
logging = require('../../../logging');
|
||||
|
||||
module.exports = function insertFixtures(options) {
|
||||
var localOptions = _.merge({
|
||||
|
@ -12,14 +11,6 @@ module.exports = function insertFixtures(options) {
|
|||
return Promise.mapSeries(fixtures.models, function (model) {
|
||||
logging.info('Model: ' + model.name);
|
||||
|
||||
// The Post model fixtures need a `published_at` date, where at least the seconds
|
||||
// are different, otherwise `prev_post` and `next_post` helpers won't workd with
|
||||
// them.
|
||||
if (model.name === 'Post') {
|
||||
_.forEach(model.entries, function (post, index) {
|
||||
post.published_at = moment().add(index, 'seconds');
|
||||
});
|
||||
}
|
||||
return fixtures.utils.addFixturesForModel(model, localOptions);
|
||||
}).then(function () {
|
||||
return Promise.mapSeries(fixtures.relations, function (relation) {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
// # 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'),
|
||||
baseUtils = require('../../../models/base/utils'),
|
||||
sequence = require('../../../utils/sequence'),
|
||||
var _ = require('lodash'),
|
||||
Promise = require('bluebird'),
|
||||
models = require('../../../models'),
|
||||
baseUtils = require('../../../models/base/utils'),
|
||||
sequence = require('../../../utils/sequence'),
|
||||
moment = require('moment'),
|
||||
|
||||
fixtures = require('./fixtures'),
|
||||
fixtures = require('./fixtures'),
|
||||
|
||||
// Private
|
||||
matchFunc,
|
||||
|
@ -95,6 +96,21 @@ fetchRelationData = function fetchRelationData(relation, options) {
|
|||
* @returns {Promise.<*>}
|
||||
*/
|
||||
addFixturesForModel = function addFixturesForModel(modelFixture, options) {
|
||||
// Clone the fixtures as they get changed in this function.
|
||||
// The initial blog posts will be added a `published_at` property, which
|
||||
// would change the fixturesHash.
|
||||
modelFixture = _.cloneDeep(modelFixture);
|
||||
// The Post model fixtures need a `published_at` date, where at least the seconds
|
||||
// are different, otherwise `prev_post` and `next_post` helpers won't workd with
|
||||
// them.
|
||||
if (modelFixture.name === 'Post') {
|
||||
_.forEach(modelFixture.entries, function (post, index) {
|
||||
if (!post.published_at) {
|
||||
post.published_at = moment().add(index, 'seconds');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.mapSeries(modelFixture.entries, function (entry) {
|
||||
// CASE: if id is specified, only query by id
|
||||
return models[modelFixture.name].findOne(entry.id ? {id: entry.id} : entry, options).then(function (found) {
|
||||
|
|
Loading…
Add table
Reference in a new issue