0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00

Fix tests to ensure correct post is being checked

Refs #3473
- Change tests to not assume that all inserted fixture data
  will end up with the same millisecond-precision time for
  results sorting.  If a test is set up to check the contents
  of a specific fixture extract it explictly from the results.
This commit is contained in:
Jason Williams 2014-08-01 05:04:40 +00:00
parent b0fdf4d078
commit 0ebccc5c65

View file

@ -21,6 +21,10 @@ describe('Post Model', function () {
should.exist(PostModel);
function extractFirstPost(posts) {
return _.filter(posts, { id: 1 })[0];
}
function checkFirstPostData(firstPost) {
should.not.exist(firstPost.author_id);
firstPost.author.should.be.an.Object;
@ -54,8 +58,14 @@ describe('Post Model', function () {
.then(function (results) {
should.exist(results);
results.length.should.be.above(0);
firstPost = results.models[0].toJSON();
checkFirstPostData(firstPost);
posts = results.models.map(function (model) {
return model.toJSON();
});
// the first post in the result is not always the post at
// position 0 in the fixture data so we need to use extractFirstPost
// to get the post with id: 1
checkFirstPostData(extractFirstPost(posts));
done();
}).catch(done);
@ -86,9 +96,10 @@ describe('Post Model', function () {
results.meta.pagination.pages.should.equal(1);
results.posts.length.should.equal(4);
firstPost = results.posts[0];
checkFirstPostData(firstPost);
// the first post in the result is not always the post at
// position 0 in the fixture data so we need to use extractFirstPost
// to get the post with id: 1
checkFirstPostData(extractFirstPost(results.posts));
done();
}).catch(done);