0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Adding a test for published at.

This commit is contained in:
Hannah Wolfe 2013-06-16 14:37:32 +01:00
parent 74dc64f1a3
commit 382da5daf0

View file

@ -21,8 +21,9 @@
it('can browse', function (done) { it('can browse', function (done) {
PostModel.browse().then(function (results) { PostModel.browse().then(function (results) {
should.exist(results); should.exist(results);
results.length.should.equal(2); results.length.should.equal(2);
// should be in published_at, DESC order
results.models[0].attributes.published_at.should.be.above(results.models[1].attributes.published_at);
done(); done();
}).then(null, done); }).then(null, done);
@ -33,15 +34,12 @@
PostModel.browse().then(function (results) { PostModel.browse().then(function (results) {
should.exist(results); should.exist(results);
results.length.should.be.above(0); results.length.should.be.above(0);
firstPost = results.models[0]; firstPost = results.models[0];
return PostModel.read({slug: firstPost.attributes.slug}); return PostModel.read({slug: firstPost.attributes.slug});
}).then(function (found) { }).then(function (found) {
should.exist(found); should.exist(found);
found.attributes.title.should.equal(firstPost.attributes.title); found.attributes.title.should.equal(firstPost.attributes.title);
done(); done();
@ -52,23 +50,16 @@
var firstPost; var firstPost;
PostModel.browse().then(function (results) { PostModel.browse().then(function (results) {
should.exist(results); should.exist(results);
results.length.should.be.above(0); results.length.should.be.above(0);
firstPost = results.models[0]; firstPost = results.models[0];
return PostModel.edit({id: firstPost.id, title: "new title"}); return PostModel.edit({id: firstPost.id, title: "new title"});
}).then(function (edited) { }).then(function (edited) {
should.exist(edited); should.exist(edited);
edited.attributes.title.should.equal('new title'); edited.attributes.title.should.equal('new title');
done(); done();
}).then(null, done); }).then(null, done);
}); });
@ -79,12 +70,9 @@
}; };
PostModel.add(newPost).then(function (createdPost) { PostModel.add(newPost).then(function (createdPost) {
return new PostModel({id: createdPost.id}).fetch(); return new PostModel({id: createdPost.id}).fetch();
}).then(function (createdPost) { }).then(function (createdPost) {
should.exist(createdPost); should.exist(createdPost);
createdPost.has('uuid').should.equal(true); createdPost.has('uuid').should.equal(true);
createdPost.get('status').should.equal('draft'); createdPost.get('status').should.equal('draft');
createdPost.get('title').should.equal(newPost.title, "title is correct"); createdPost.get('title').should.equal(newPost.title, "title is correct");
@ -94,9 +82,9 @@
// Set the status to published to check that `published_at` is set. // Set the status to published to check that `published_at` is set.
return createdPost.save({status: 'published'}); return createdPost.save({status: 'published'});
}).then(function (publishedPost) {
}).then(function(publishedPost) {
publishedPost.get('published_at').should.be.instanceOf(Date); publishedPost.get('published_at').should.be.instanceOf(Date);
done(); done();
}).then(null, done); }).then(null, done);
@ -105,32 +93,24 @@
it('can delete', function (done) { it('can delete', function (done) {
var firstPostId; var firstPostId;
PostModel.browse().then(function (results) { PostModel.browse().then(function (results) {
should.exist(results); should.exist(results);
results.length.should.be.above(0); results.length.should.be.above(0);
firstPostId = results.models[0].id; firstPostId = results.models[0].id;
return PostModel.destroy(firstPostId); return PostModel.destroy(firstPostId);
}).then(function () { }).then(function () {
return PostModel.browse(); return PostModel.browse();
}).then(function (newResults) { }).then(function (newResults) {
var ids, hasDeletedId; var ids, hasDeletedId;
ids = _.pluck(newResults.models, "id"); ids = _.pluck(newResults.models, "id");
hasDeletedId = _.any(ids, function (id) { hasDeletedId = _.any(ids, function (id) {
return id === firstPostId; return id === firstPostId;
}); });
hasDeletedId.should.equal(false); hasDeletedId.should.equal(false);
done(); done();
}).then(null, done); }).then(null, done);
}); });
@ -140,64 +120,39 @@
helpers.insertMorePosts().then(function () { helpers.insertMorePosts().then(function () {
return PostModel.findPage({page: 2}); return PostModel.findPage({page: 2});
}).then(function (paginationResult) { }).then(function (paginationResult) {
paginationResult.page.should.equal(2); paginationResult.page.should.equal(2);
paginationResult.limit.should.equal(15); paginationResult.limit.should.equal(15);
paginationResult.posts.length.should.equal(15); paginationResult.posts.length.should.equal(15);
paginationResult.pages.should.equal(4); paginationResult.pages.should.equal(4);
return PostModel.findPage({page: 5}); return PostModel.findPage({page: 5});
}).then(function (paginationResult) { }).then(function (paginationResult) {
paginationResult.page.should.equal(5); paginationResult.page.should.equal(5);
paginationResult.limit.should.equal(15); paginationResult.limit.should.equal(15);
paginationResult.posts.length.should.equal(0); paginationResult.posts.length.should.equal(0);
paginationResult.pages.should.equal(4); paginationResult.pages.should.equal(4);
return PostModel.findPage({limit: 30}); return PostModel.findPage({limit: 30});
}).then(function (paginationResult) { }).then(function (paginationResult) {
paginationResult.page.should.equal(1); paginationResult.page.should.equal(1);
paginationResult.limit.should.equal(30); paginationResult.limit.should.equal(30);
paginationResult.posts.length.should.equal(30); paginationResult.posts.length.should.equal(30);
paginationResult.pages.should.equal(2); paginationResult.pages.should.equal(2);
return PostModel.findPage({limit: 10, page: 2, where: {language: 'fr'}}); return PostModel.findPage({limit: 10, page: 2, where: {language: 'fr'}});
}).then(function (paginationResult) { }).then(function (paginationResult) {
paginationResult.page.should.equal(2); paginationResult.page.should.equal(2);
paginationResult.limit.should.equal(10); paginationResult.limit.should.equal(10);
paginationResult.posts.length.should.equal(10); paginationResult.posts.length.should.equal(10);
paginationResult.pages.should.equal(3); paginationResult.pages.should.equal(3);
return PostModel.findPage({limit: 10, page: 2, status: 'all'}); return PostModel.findPage({limit: 10, page: 2, status: 'all'});
}).then(function (paginationResult) { }).then(function (paginationResult) {
paginationResult.pages.should.equal(11); paginationResult.pages.should.equal(11);
done(); done();
}).then(null, done); }).then(null, done);
}); });
}); });
}()); }());