0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-01 02:41:39 -05:00

Fixed posts_meta relation in test fixtures

refs d9dbcf6147

- Fixes broken commit
This commit is contained in:
Nazar Gargol 2020-09-17 20:46:45 +12:00
parent d9dbcf6147
commit d177852d1f
4 changed files with 51 additions and 19 deletions

View file

@ -53,6 +53,9 @@ describe('Post Model', function () {
})
.then(function () {
return testUtils.truncate('posts');
})
.then(function () {
return testUtils.truncate('posts_meta');
});
});
@ -179,6 +182,9 @@ describe('Post Model', function () {
})
.then(function () {
return testUtils.truncate('posts');
})
.then(function () {
return testUtils.truncate('posts_meta');
});
});
@ -697,6 +703,9 @@ describe('Post Model', function () {
})
.then(function () {
return testUtils.truncate('posts');
})
.then(function () {
return testUtils.truncate('posts_meta');
});
});
@ -1172,6 +1181,9 @@ describe('Post Model', function () {
})
.then(function () {
return testUtils.truncate('posts');
})
.then(function () {
return testUtils.truncate('posts_meta');
});
});
@ -1354,6 +1366,9 @@ describe('Post Model', function () {
})
.then(function () {
return testUtils.truncate('posts');
})
.then(function () {
return testUtils.truncate('posts_meta');
});
});
@ -1592,6 +1607,9 @@ describe('Post Model', function () {
})
.then(function () {
return testUtils.truncate('posts');
})
.then(function () {
return testUtils.truncate('posts_meta');
});
});

View file

@ -20,10 +20,11 @@ describe('RSS: Generate Feed', function () {
return post.status === 'published' && post.type === 'post';
});
posts[2].meta_description = 'test stuffs';
_.each(posts, function (post) {
post.url = '/' + post.slug + '/';
post.primary_author = {name: 'Joe Bloggs'};
post.meta_description = post.posts_meta && post.posts_meta.meta_description;
});
});

View file

@ -51,10 +51,7 @@ DataGenerator.Content = {
feature_image: 'http://placekitten.com/500/200',
published_at: new Date('2015-01-03'),
featured: true,
uuid: '2ac6b4f6-e1f3-406c-9247-c94a0496d39d',
posts_meta: {
meta_description: 'test stuff'
}
uuid: '2ac6b4f6-e1f3-406c-9247-c94a0496d39d'
},
{
id: ObjectId.generate(),
@ -807,6 +804,14 @@ DataGenerator.forKnex = (function () {
}
];
const posts_meta = [
{
id: ObjectId.generate(),
post_id: DataGenerator.Content.posts[2].id,
meta_description: 'test stuff'
}
];
// this is not pretty, but the fastest
// it relies on the created posts/tags
const posts_tags = [
@ -992,6 +997,7 @@ DataGenerator.forKnex = (function () {
invites,
posts,
tags,
posts_meta,
posts_tags,
posts_authors,
roles,

View file

@ -63,24 +63,31 @@ fixtures = {
insertPostsAndTags: function insertPostsAndTags() {
return Promise.map(DataGenerator.forKnex.tags, function (tag) {
return models.Tag.add(tag, module.exports.context.internal);
}).then(function () {
return Promise.each(_.cloneDeep(DataGenerator.forKnex.posts), function (post) {
let postTagRelations = _.filter(DataGenerator.forKnex.posts_tags, {post_id: post.id});
let postAuthorsRelations = _.filter(DataGenerator.forKnex.posts_authors, {post_id: post.id});
postTagRelations = _.map(postTagRelations, function (postTagRelation) {
return _.find(DataGenerator.forKnex.tags, {id: postTagRelation.tag_id});
})
.then(function () {
return Promise.map(DataGenerator.forKnex.posts_meta, function (postMeta) {
return models.PostsMeta.add(postMeta, module.exports.context.internal);
});
})
.then(function () {
return Promise.each(_.cloneDeep(DataGenerator.forKnex.posts), function (post) {
let postTagRelations = _.filter(DataGenerator.forKnex.posts_tags, {post_id: post.id});
let postAuthorsRelations = _.filter(DataGenerator.forKnex.posts_authors, {post_id: post.id});
postAuthorsRelations = _.map(postAuthorsRelations, function (postAuthorsRelation) {
return _.find(DataGenerator.forKnex.users, {id: postAuthorsRelation.author_id});
postTagRelations = _.map(postTagRelations, function (postTagRelation) {
return _.find(DataGenerator.forKnex.tags, {id: postTagRelation.tag_id});
});
postAuthorsRelations = _.map(postAuthorsRelations, function (postAuthorsRelation) {
return _.find(DataGenerator.forKnex.users, {id: postAuthorsRelation.author_id});
});
post.tags = postTagRelations;
post.authors = postAuthorsRelations;
return models.Post.add(post, module.exports.context.internal);
});
post.tags = postTagRelations;
post.authors = postAuthorsRelations;
return models.Post.add(post, module.exports.context.internal);
});
});
},
insertMultiAuthorPosts: function insertMultiAuthorPosts() {