Skip to content

Commit

Permalink
🐛 Add published_at to post model fixtures (#8573)
Browse files Browse the repository at this point in the history
closes #8562
- before we create our model fixtures, we assign a `published_at` property with a difference of 1 second for each blog post, so the `prev_post` and `next_post` helpers work correctly
  • Loading branch information
aileen authored and kevinansfield committed Jun 13, 2017
1 parent eec5896 commit 57f8367
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/server/data/migrations/init/2-create-fixtures.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var Promise = require('bluebird'),
_ = require('lodash'),
fixtures = require('../../schema/fixtures'),
logging = require('../../../logging');
logging = require('../../../logging'),
moment = require('moment');

module.exports = function insertFixtures(options) {
var localOptions = _.merge({
Expand All @@ -10,6 +11,15 @@ 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) {
Expand Down

0 comments on commit 57f8367

Please sign in to comment.