mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -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'),
|
var Promise = require('bluebird'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
fixtures = require('../../schema/fixtures'),
|
fixtures = require('../../schema/fixtures'),
|
||||||
logging = require('../../../logging'),
|
logging = require('../../../logging');
|
||||||
moment = require('moment');
|
|
||||||
|
|
||||||
module.exports = function insertFixtures(options) {
|
module.exports = function insertFixtures(options) {
|
||||||
var localOptions = _.merge({
|
var localOptions = _.merge({
|
||||||
|
@ -12,14 +11,6 @@ module.exports = function insertFixtures(options) {
|
||||||
return Promise.mapSeries(fixtures.models, function (model) {
|
return Promise.mapSeries(fixtures.models, function (model) {
|
||||||
logging.info('Model: ' + model.name);
|
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);
|
return fixtures.utils.addFixturesForModel(model, localOptions);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
return Promise.mapSeries(fixtures.relations, function (relation) {
|
return Promise.mapSeries(fixtures.relations, function (relation) {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
// # Fixture Utils
|
// # Fixture Utils
|
||||||
// Standalone file which can be required to help with advanced operations on the fixtures.json file
|
// Standalone file which can be required to help with advanced operations on the fixtures.json file
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
Promise = require('bluebird'),
|
Promise = require('bluebird'),
|
||||||
models = require('../../../models'),
|
models = require('../../../models'),
|
||||||
baseUtils = require('../../../models/base/utils'),
|
baseUtils = require('../../../models/base/utils'),
|
||||||
sequence = require('../../../utils/sequence'),
|
sequence = require('../../../utils/sequence'),
|
||||||
|
moment = require('moment'),
|
||||||
|
|
||||||
fixtures = require('./fixtures'),
|
fixtures = require('./fixtures'),
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
matchFunc,
|
matchFunc,
|
||||||
|
@ -95,6 +96,21 @@ fetchRelationData = function fetchRelationData(relation, options) {
|
||||||
* @returns {Promise.<*>}
|
* @returns {Promise.<*>}
|
||||||
*/
|
*/
|
||||||
addFixturesForModel = function addFixturesForModel(modelFixture, options) {
|
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) {
|
return Promise.mapSeries(modelFixture.entries, function (entry) {
|
||||||
// CASE: if id is specified, only query by id
|
// CASE: if id is specified, only query by id
|
||||||
return models[modelFixture.name].findOne(entry.id ? {id: entry.id} : entry, options).then(function (found) {
|
return models[modelFixture.name].findOne(entry.id ? {id: entry.id} : entry, options).then(function (found) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue