From e7529de7738bf31452766aaa47a5d798f13d5d7a Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Fri, 6 Apr 2018 15:31:00 +0200 Subject: [PATCH] Tests: tidied up `integration/models/model_posts_spec.js` no issue - simple cleanup - no functional change --- .../integration/model/model_posts_spec.js | 266 +++++++++--------- 1 file changed, 130 insertions(+), 136 deletions(-) diff --git a/core/test/integration/model/model_posts_spec.js b/core/test/integration/model/model_posts_spec.js index 94193157b8..a2854d3f23 100644 --- a/core/test/integration/model/model_posts_spec.js +++ b/core/test/integration/model/model_posts_spec.js @@ -7,10 +7,7 @@ var should = require('should'), sequence = require('../../../server/lib/promise/sequence'), settingsCache = require('../../../server/services/settings/cache'), ghostBookshelf = require('../../../server/models/base'), - PostModel = require('../../../server/models/post').Post, - TagModel = require('../../../server/models/tag').Tag, - UserModel = require('../../../server/models/user').User, - RoleModel = require('../../../server/models/role').Role, + models = require('../../../server/models'), common = require('../../../server/lib/common'), configUtils = require('../../utils/configUtils'), DataGenerator = testUtils.DataGenerator, @@ -35,9 +32,6 @@ describe('Post Model', function () { sandbox.restore(); }); - should.exist(TagModel); - should.exist(PostModel); - describe('Single author posts', function () { afterEach(function () { configUtils.restore(); @@ -106,7 +100,7 @@ describe('Post Model', function () { }); it('can findAll', function (done) { - PostModel.findAll().then(function (results) { + models.Post.findAll().then(function (results) { should.exist(results); results.length.should.be.above(1); done(); @@ -116,7 +110,7 @@ describe('Post Model', function () { it('can findAll, returning all related data', function (done) { var options = {withRelated: ['author', 'authors', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']}; - PostModel.findAll(options) + models.Post.findAll(options) .then(function (results) { should.exist(results); results.length.should.be.above(0); @@ -137,7 +131,7 @@ describe('Post Model', function () { withRelated: ['author', 'fields', 'tags', 'created_by', 'updated_by', 'published_by'] }; - PostModel.findAll(options) + models.Post.findAll(options) .then(function (results) { should.exist(results); results.length.should.be.above(0); @@ -163,7 +157,7 @@ describe('Post Model', function () { }); it('can findPage (default)', function (done) { - PostModel.findPage().then(function (results) { + models.Post.findPage().then(function (results) { should.exist(results); results.meta.pagination.page.should.equal(1); @@ -176,7 +170,7 @@ describe('Post Model', function () { }); it('can findPage, returning all related data', function (done) { - PostModel.findPage({withRelated: ['author', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']}) + models.Post.findPage({withRelated: ['author', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']}) .then(function (results) { should.exist(results); @@ -193,7 +187,7 @@ describe('Post Model', function () { }); it('returns computed fields when columns are asked for explicitly', function (done) { - PostModel.findPage({columns: ['id', 'slug', 'url', 'mobiledoc']}).then(function (results) { + models.Post.findPage({columns: ['id', 'slug', 'url', 'mobiledoc']}).then(function (results) { should.exist(results); var post = _.find(results.posts, {slug: testUtils.DataGenerator.Content.posts[0].slug}); @@ -209,7 +203,7 @@ describe('Post Model', function () { }); it('ignores columns that do not exist', function (done) { - PostModel.findPage({columns: ['id', 'slug', 'doesnotexist']}).then(function (results) { + models.Post.findPage({columns: ['id', 'slug', 'doesnotexist']}).then(function (results) { should.exist(results); var post = _.find(results.posts, {slug: testUtils.DataGenerator.Content.posts[0].slug}); @@ -225,21 +219,21 @@ describe('Post Model', function () { testUtils.fixtures.insertExtraPosts().then(function () { return testUtils.fixtures.insertExtraPostsTags(); }).then(function () { - return PostModel.findPage({page: 2}); + return models.Post.findPage({page: 2}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(2); paginationResult.meta.pagination.limit.should.equal(15); paginationResult.meta.pagination.pages.should.equal(4); paginationResult.posts.length.should.equal(15); - return PostModel.findPage({page: 5}); + return models.Post.findPage({page: 5}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(5); paginationResult.meta.pagination.limit.should.equal(15); paginationResult.meta.pagination.pages.should.equal(4); paginationResult.posts.length.should.equal(0); - return PostModel.findPage({limit: 30}); + return models.Post.findPage({limit: 30}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(1); paginationResult.meta.pagination.limit.should.equal(30); @@ -247,7 +241,7 @@ describe('Post Model', function () { paginationResult.posts.length.should.equal(30); // Test both boolean formats - return PostModel.findPage({limit: 10, staticPages: true}); + return models.Post.findPage({limit: 10, staticPages: true}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(1); paginationResult.meta.pagination.limit.should.equal(10); @@ -255,7 +249,7 @@ describe('Post Model', function () { paginationResult.posts.length.should.equal(1); // Test both boolean formats - return PostModel.findPage({limit: 10, staticPages: '1'}); + return models.Post.findPage({limit: 10, staticPages: '1'}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(1); paginationResult.meta.pagination.limit.should.equal(10); @@ -263,7 +257,7 @@ describe('Post Model', function () { paginationResult.posts.length.should.equal(1); // Test featured pages - return PostModel.findPage({limit: 10, filter: 'featured:true'}); + return models.Post.findPage({limit: 10, filter: 'featured:true'}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(1); paginationResult.meta.pagination.limit.should.equal(10); @@ -271,18 +265,18 @@ describe('Post Model', function () { paginationResult.posts.length.should.equal(10); // Test both boolean formats for featured pages - return PostModel.findPage({limit: 10, filter: 'featured:1'}); + return models.Post.findPage({limit: 10, filter: 'featured:1'}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(1); paginationResult.meta.pagination.limit.should.equal(10); paginationResult.meta.pagination.pages.should.equal(6); paginationResult.posts.length.should.equal(10); - return PostModel.findPage({limit: 10, page: 2, status: 'all'}); + return models.Post.findPage({limit: 10, page: 2, status: 'all'}); }).then(function (paginationResult) { paginationResult.meta.pagination.pages.should.equal(11); - return PostModel.findPage({limit: 'all', status: 'all'}); + return models.Post.findPage({limit: 'all', status: 'all'}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(1); paginationResult.meta.pagination.limit.should.equal('all'); @@ -298,28 +292,28 @@ describe('Post Model', function () { return testUtils.fixtures.insertExtraPostsTags(); }).then(function () { // Test tag filter - return PostModel.findPage({page: 1, filter: 'tags:bacon'}); + return models.Post.findPage({page: 1, filter: 'tags:bacon'}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(1); paginationResult.meta.pagination.limit.should.equal(15); paginationResult.meta.pagination.pages.should.equal(1); paginationResult.posts.length.should.equal(2); - return PostModel.findPage({page: 1, filter: 'tags:kitchen-sink'}); + return models.Post.findPage({page: 1, filter: 'tags:kitchen-sink'}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(1); paginationResult.meta.pagination.limit.should.equal(15); paginationResult.meta.pagination.pages.should.equal(1); paginationResult.posts.length.should.equal(2); - return PostModel.findPage({page: 1, filter: 'tags:injection'}); + return models.Post.findPage({page: 1, filter: 'tags:injection'}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(1); paginationResult.meta.pagination.limit.should.equal(15); paginationResult.meta.pagination.pages.should.equal(2); paginationResult.posts.length.should.equal(15); - return PostModel.findPage({page: 2, filter: 'tags:injection'}); + return models.Post.findPage({page: 2, filter: 'tags:injection'}); }).then(function (paginationResult) { paginationResult.meta.pagination.page.should.equal(2); paginationResult.meta.pagination.limit.should.equal(15); @@ -331,7 +325,7 @@ describe('Post Model', function () { }); it('can NOT findPage for a page that overflows the datatype', function (done) { - PostModel.findPage({page: 5700000000055345439587894375457849375284932759842375894372589243758947325894375894275894275894725897432859724309}) + models.Post.findPage({page: 5700000000055345439587894375457849375284932759842375894372589243758947325894375894275894275894725897432859724309}) .then(function (paginationResult) { should.exist(paginationResult.meta); @@ -354,13 +348,13 @@ describe('Post Model', function () { it('can findOne', function (done) { var firstPost; - PostModel.findPage().then(function (results) { + models.Post.findPage().then(function (results) { should.exist(results); should.exist(results.posts); results.posts.length.should.be.above(0); firstPost = results.posts[0]; - return PostModel.findOne({slug: firstPost.slug}); + return models.Post.findOne({slug: firstPost.slug}); }).then(function (found) { should.exist(found); found.attributes.title.should.equal(firstPost.title); @@ -372,7 +366,7 @@ describe('Post Model', function () { it('can findOne, returning all related data', function (done) { var firstPost; - PostModel.findOne({}, {withRelated: ['author', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']}) + models.Post.findOne({}, {withRelated: ['author', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']}) .then(function (result) { should.exist(result); firstPost = result.toJSON(); @@ -384,7 +378,7 @@ describe('Post Model', function () { }); it('can findOne, returning a slug only permalink', function (done) { - PostModel.findOne({id: testUtils.DataGenerator.Content.posts[0].id}) + models.Post.findOne({id: testUtils.DataGenerator.Content.posts[0].id}) .then(function (result) { should.exist(result); var firstPost = result.toJSON(); @@ -403,7 +397,7 @@ describe('Post Model', function () { }[key]; }); - PostModel.findOne({id: testUtils.DataGenerator.Content.posts[0].id}) + models.Post.findOne({id: testUtils.DataGenerator.Content.posts[0].id}) .then(function (result) { should.exist(result); var firstPost = result.toJSON(); @@ -433,14 +427,14 @@ describe('Post Model', function () { it('can change title', function (done) { var postId = testUtils.DataGenerator.Content.posts[0].id; - PostModel.findOne({id: postId}).then(function (results) { + models.Post.findOne({id: postId}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.id.should.equal(postId); post.title.should.not.equal('new title'); - return PostModel.edit({title: 'new title'}, _.extend({}, context, {id: postId})); + return models.Post.edit({title: 'new title'}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.title.should.equal('new title'); @@ -456,13 +450,13 @@ describe('Post Model', function () { it('[failure] custom excerpt soft limit reached', function (done) { var postId = testUtils.DataGenerator.Content.posts[0].id; - PostModel.findOne({id: postId}).then(function (results) { + models.Post.findOne({id: postId}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.id.should.equal(postId); - return PostModel.edit({ + return models.Post.edit({ custom_excerpt: new Array(302).join('a') }, _.extend({}, context, {id: postId})); }).then(function () { @@ -476,13 +470,13 @@ describe('Post Model', function () { it('[success] custom excerpt soft limit respected', function (done) { var postId = testUtils.DataGenerator.Content.posts[0].id; - PostModel.findOne({id: postId}).then(function (results) { + models.Post.findOne({id: postId}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.id.should.equal(postId); - return PostModel.edit({ + return models.Post.edit({ custom_excerpt: new Array(300).join('a') }, _.extend({}, context, {id: postId})); }).then(function (edited) { @@ -494,11 +488,11 @@ describe('Post Model', function () { it('can change title to number', function (done) { var postId = testUtils.DataGenerator.Content.posts[0].id; - PostModel.findOne({id: postId}).then(function (results) { + models.Post.findOne({id: postId}).then(function (results) { should.exist(results); var post = results.toJSON(); post.title.should.not.equal('123'); - return PostModel.edit({title: 123}, _.extend({}, context, {id: postId})); + return models.Post.edit({title: 123}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.title.should.equal('123'); @@ -509,11 +503,11 @@ describe('Post Model', function () { it('converts html to plaintext', function (done) { var postId = testUtils.DataGenerator.Content.posts[0].id; - PostModel.findOne({id: postId}).then(function (results) { + models.Post.findOne({id: postId}).then(function (results) { should.exist(results); results.attributes.html.should.match(/HTML Ipsum Presents/); should.not.exist(results.attributes.plaintext); - return PostModel.edit({updated_at: results.attributes.updated_at}, _.extend({}, context, {id: postId})); + return models.Post.edit({updated_at: results.attributes.updated_at}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); @@ -526,14 +520,14 @@ describe('Post Model', function () { it('can publish draft post', function (done) { var postId = testUtils.DataGenerator.Content.posts[3].id; - PostModel.findOne({id: postId, status: 'draft'}).then(function (results) { + models.Post.findOne({id: postId, status: 'draft'}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.id.should.equal(postId); post.status.should.equal('draft'); - return PostModel.edit({status: 'published'}, _.extend({}, context, {id: postId})); + return models.Post.edit({status: 'published'}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('published'); @@ -549,14 +543,14 @@ describe('Post Model', function () { it('can unpublish published post', function (done) { var postId = testUtils.DataGenerator.Content.posts[0].id; - PostModel.findOne({id: postId}).then(function (results) { + models.Post.findOne({id: postId}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.id.should.equal(postId); post.status.should.equal('published'); - return PostModel.edit({status: 'draft'}, _.extend({}, context, {id: postId})); + return models.Post.edit({status: 'draft'}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('draft'); @@ -572,7 +566,7 @@ describe('Post Model', function () { it('draft -> scheduled without published_at update', function (done) { var post; - PostModel.findOne({status: 'draft'}).then(function (results) { + models.Post.findOne({status: 'draft'}).then(function (results) { should.exist(results); post = results.toJSON(); post.status.should.equal('draft'); @@ -580,7 +574,7 @@ describe('Post Model', function () { results.set('published_at', null); return results.save(); }).then(function () { - return PostModel.edit({ + return models.Post.edit({ status: 'scheduled' }, _.extend({}, context, {id: post.id})); }).then(function () { @@ -595,14 +589,14 @@ describe('Post Model', function () { it('draft -> scheduled: expect update of published_at', function (done) { var newPublishedAt = moment().add(1, 'day').toDate(); - PostModel.findOne({status: 'draft'}).then(function (results) { + models.Post.findOne({status: 'draft'}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.status.should.equal('draft'); - return PostModel.edit({ + return models.Post.edit({ status: 'scheduled', published_at: newPublishedAt }, _.extend({}, context, {id: post.id})); @@ -622,14 +616,14 @@ describe('Post Model', function () { }); it('scheduled -> draft: expect unschedule', function (done) { - PostModel.findOne({status: 'scheduled'}).then(function (results) { + models.Post.findOne({status: 'scheduled'}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.status.should.equal('scheduled'); - return PostModel.edit({ + return models.Post.edit({ status: 'draft' }, _.extend({}, context, {id: post.id})); }).then(function (edited) { @@ -645,14 +639,14 @@ describe('Post Model', function () { }); it('scheduled -> scheduled with updated published_at', function (done) { - PostModel.findOne({status: 'scheduled'}).then(function (results) { + models.Post.findOne({status: 'scheduled'}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.status.should.equal('scheduled'); - return PostModel.edit({ + return models.Post.edit({ status: 'scheduled', published_at: moment().add(20, 'days').toDate() }, _.extend({}, context, {id: post.id})); @@ -669,14 +663,14 @@ describe('Post Model', function () { }); it('scheduled -> scheduled with unchanged published_at', function (done) { - PostModel.findOne({status: 'scheduled'}).then(function (results) { + models.Post.findOne({status: 'scheduled'}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.status.should.equal('scheduled'); - return PostModel.edit({ + return models.Post.edit({ status: 'scheduled' }, _.extend({}, context, {id: post.id})); }).then(function (edited) { @@ -693,7 +687,7 @@ describe('Post Model', function () { it('scheduled -> scheduled with unchanged published_at (within the 2 minutes window)', function (done) { var post; - PostModel.findOne({status: 'scheduled'}).then(function (results) { + models.Post.findOne({status: 'scheduled'}).then(function (results) { should.exist(results); post = results.toJSON(); post.status.should.equal('scheduled'); @@ -708,7 +702,7 @@ describe('Post Model', function () { return Promise.delay(1000 * 3); }).then(function () { - return PostModel.edit({ + return models.Post.edit({ status: 'scheduled' }, _.extend({}, context, {id: post.id})); }).then(function (edited) { @@ -725,14 +719,14 @@ describe('Post Model', function () { it('published -> scheduled and expect update of published_at', function (done) { var postId = testUtils.DataGenerator.Content.posts[0].id; - PostModel.findOne({id: postId}).then(function (results) { + models.Post.findOne({id: postId}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.id.should.equal(postId); post.status.should.equal('published'); - return PostModel.edit({ + return models.Post.edit({ status: 'scheduled', published_at: moment().add(1, 'day').toDate() }, _.extend({}, context, {id: postId})); @@ -748,14 +742,14 @@ describe('Post Model', function () { it('can convert draft post to page and back', function (done) { var postId = testUtils.DataGenerator.Content.posts[3].id; - PostModel.findOne({id: postId, status: 'draft'}).then(function (results) { + models.Post.findOne({id: postId, status: 'draft'}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.id.should.equal(postId); post.status.should.equal('draft'); - return PostModel.edit({page: 1}, _.extend({}, context, {id: postId})); + return models.Post.edit({page: 1}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('draft'); @@ -765,7 +759,7 @@ describe('Post Model', function () { should.exist(eventsTriggered['post.deleted']); should.exist(eventsTriggered['page.added']); - return PostModel.edit({page: 0}, _.extend({}, context, {id: postId})); + return models.Post.edit({page: 0}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('draft'); @@ -782,13 +776,13 @@ describe('Post Model', function () { }); it('can convert draft to schedule AND post to page and back', function (done) { - PostModel.findOne({status: 'draft'}).then(function (results) { + models.Post.findOne({status: 'draft'}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.status.should.equal('draft'); - return PostModel.edit({ + return models.Post.edit({ page: 1, status: 'scheduled', published_at: moment().add(10, 'days') @@ -803,7 +797,7 @@ describe('Post Model', function () { should.exist(eventsTriggered['page.added']); should.exist(eventsTriggered['page.scheduled']); - return PostModel.edit({page: 0}, _.extend({}, context, {id: edited.id})); + return models.Post.edit({page: 0}, _.extend({}, context, {id: edited.id})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('scheduled'); @@ -822,14 +816,14 @@ describe('Post Model', function () { it('can convert published post to page and back', function (done) { var postId = testUtils.DataGenerator.Content.posts[0].id; - PostModel.findOne({id: postId}).then(function (results) { + models.Post.findOne({id: postId}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.id.should.equal(postId); post.status.should.equal('published'); - return PostModel.edit({page: 1}, _.extend({}, context, {id: postId})); + return models.Post.edit({page: 1}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('published'); @@ -841,7 +835,7 @@ describe('Post Model', function () { should.exist(eventsTriggered['page.added']); should.exist(eventsTriggered['page.published']); - return PostModel.edit({page: 0}, _.extend({}, context, {id: postId})); + return models.Post.edit({page: 0}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('published'); @@ -860,14 +854,14 @@ describe('Post Model', function () { it('can change type and status at the same time', function (done) { var postId = testUtils.DataGenerator.Content.posts[3].id; - PostModel.findOne({id: postId, status: 'draft'}).then(function (results) { + models.Post.findOne({id: postId, status: 'draft'}).then(function (results) { var post; should.exist(results); post = results.toJSON(); post.id.should.equal(postId); post.status.should.equal('draft'); - return PostModel.edit({page: 1, status: 'published'}, _.extend({}, context, {id: postId})); + return models.Post.edit({page: 1, status: 'published'}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('published'); @@ -878,7 +872,7 @@ describe('Post Model', function () { should.exist(eventsTriggered['page.added']); should.exist(eventsTriggered['page.published']); - return PostModel.edit({page: 0, status: 'draft'}, _.extend({}, context, {id: postId})); + return models.Post.edit({page: 0, status: 'draft'}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('draft'); @@ -897,7 +891,7 @@ describe('Post Model', function () { var newPost = testUtils.DataGenerator.forModel.posts[2], postId; - PostModel.add(newPost, context).then(function (results) { + models.Post.add(newPost, context).then(function (results) { var post; should.exist(results); post = results.toJSON(); @@ -908,7 +902,7 @@ describe('Post Model', function () { should.not.exist(post.published_at); // Test changing an unrelated property - return PostModel.edit({title: 'Hello World'}, _.extend({}, context, {id: postId})); + return models.Post.edit({title: 'Hello World'}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('draft'); @@ -916,7 +910,7 @@ describe('Post Model', function () { should.not.exist(edited.attributes.published_at); // Test changing status and published_by on its own - return PostModel.edit({published_by: 4}, _.extend({}, context, {id: postId})); + return models.Post.edit({published_by: 4}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('draft'); @@ -930,7 +924,7 @@ describe('Post Model', function () { it('cannot override the published_by setting', function (done) { var postId = testUtils.DataGenerator.Content.posts[3].id; - PostModel.findOne({id: postId, status: 'draft'}).then(function (results) { + models.Post.findOne({id: postId, status: 'draft'}).then(function (results) { var post; should.exist(results); post = results.toJSON(); @@ -938,14 +932,14 @@ describe('Post Model', function () { post.status.should.equal('draft'); // Test changing status and published_by at the same time - return PostModel.edit({status: 'published', published_by: 4}, _.extend({}, context, {id: postId})); + return models.Post.edit({status: 'published', published_by: 4}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('published'); edited.attributes.published_by.should.equal(context.context.user); // Test changing status and published_by on its own - return PostModel.edit({published_by: 4}, _.extend({}, context, {id: postId})); + return models.Post.edit({published_by: 4}, _.extend({}, context, {id: postId})); }).then(function (edited) { should.exist(edited); edited.attributes.status.should.equal('published'); @@ -958,7 +952,7 @@ describe('Post Model', function () { it('send empty date', function (done) { var postId = testUtils.DataGenerator.Content.posts[0].id; - PostModel + models.Post .findOne({ id: postId }) @@ -968,7 +962,7 @@ describe('Post Model', function () { post = results.toJSON(); post.id.should.equal(postId); - return PostModel.edit({created_at: ''}, _.extend({}, context, {id: postId})); + return models.Post.edit({created_at: ''}, _.extend({}, context, {id: postId})); }) .then(function () { done(new Error('This test should fail.')); @@ -998,8 +992,8 @@ describe('Post Model', function () { newPost = testUtils.DataGenerator.forModel.posts[2], newPostDB = testUtils.DataGenerator.Content.posts[2]; - PostModel.add(newPost, _.merge({withRelated: ['author']}, context)).then(function (createdPost) { - return PostModel.findOne({id: createdPost.id, status: 'all'}); + models.Post.add(newPost, _.merge({withRelated: ['author']}, context)).then(function (createdPost) { + return models.Post.findOne({id: createdPost.id, status: 'all'}); }).then(function (createdPost) { should.exist(createdPost); createdPost.has('uuid').should.equal(true); @@ -1058,7 +1052,7 @@ describe('Post Model', function () { newPost.title = 123; - PostModel.add(newPost, context).then(function (createdPost) { + models.Post.add(newPost, context).then(function (createdPost) { should.exist(createdPost); done(); }).catch(done); @@ -1067,7 +1061,7 @@ describe('Post Model', function () { it('can add, with previous published_at date', function (done) { var previousPublishedAtDate = new Date(2013, 8, 21, 12); - PostModel.add({ + models.Post.add({ status: 'published', published_at: previousPublishedAtDate, title: 'published_at test', @@ -1085,7 +1079,7 @@ describe('Post Model', function () { }); it('add draft post without published_at -> we expect no auto insert of published_at', function (done) { - PostModel.add({ + models.Post.add({ status: 'draft', title: 'draft 1', mobiledoc: markdownToMobiledoc('This is some content') @@ -1101,7 +1095,7 @@ describe('Post Model', function () { }); it('add multiple authors', function (done) { - PostModel.add({ + models.Post.add({ status: 'draft', title: 'draft 1', mobiledoc: markdownToMobiledoc('This is some content'), @@ -1119,7 +1113,7 @@ describe('Post Model', function () { }); it('add draft post with published_at -> we expect published_at to exist', function (done) { - PostModel.add({ + models.Post.add({ status: 'draft', published_at: moment().toDate(), title: 'draft 1', @@ -1136,7 +1130,7 @@ describe('Post Model', function () { }); it('add scheduled post without published_at -> we expect an error', function (done) { - PostModel.add({ + models.Post.add({ status: 'scheduled', title: 'scheduled 1', mobiledoc: markdownToMobiledoc('This is some content') @@ -1149,7 +1143,7 @@ describe('Post Model', function () { }); it('add scheduled post with published_at not in future-> we expect an error', function (done) { - PostModel.add({ + models.Post.add({ status: 'scheduled', published_at: moment().subtract(1, 'minute'), title: 'scheduled 1', @@ -1163,7 +1157,7 @@ describe('Post Model', function () { }); it('add scheduled post with published_at 1 minutes in future -> we expect an error', function (done) { - PostModel.add({ + models.Post.add({ status: 'scheduled', published_at: moment().add(1, 'minute'), title: 'scheduled 1', @@ -1176,7 +1170,7 @@ describe('Post Model', function () { }); it('add scheduled post with published_at 10 minutes in future -> we expect success', function (done) { - PostModel.add({ + models.Post.add({ status: 'scheduled', published_at: moment().add(10, 'minute'), title: 'scheduled 1', @@ -1193,7 +1187,7 @@ describe('Post Model', function () { }); it('add scheduled page with published_at 10 minutes in future -> we expect success', function (done) { - PostModel.add({ + models.Post.add({ status: 'scheduled', page: 1, published_at: moment().add(10, 'minute'), @@ -1211,7 +1205,7 @@ describe('Post Model', function () { }); it('can add default title, if it\'s missing', function (done) { - PostModel.add({ + models.Post.add({ mobiledoc: markdownToMobiledoc('Content') }, context).then(function (newPost) { should.exist(newPost); @@ -1229,8 +1223,8 @@ describe('Post Model', function () { mobiledoc: markdownToMobiledoc('Test content') }; - PostModel.add(newPost, context).then(function (createdPost) { - return PostModel.findOne({id: createdPost.id, status: 'all'}); + models.Post.add(newPost, context).then(function (createdPost) { + return models.Post.findOne({id: createdPost.id, status: 'all'}); }).then(function (createdPost) { should.exist(createdPost); createdPost.get('title').should.equal(untrimmedCreateTitle.trim()); @@ -1253,7 +1247,7 @@ describe('Post Model', function () { // Create 12 posts with the same title sequence(_.times(12, function (i) { return function () { - return PostModel.add({ + return models.Post.add({ title: 'Test Title', mobiledoc: markdownToMobiledoc('Test Content ' + (i + 1)) }, context); @@ -1290,7 +1284,7 @@ describe('Post Model', function () { mobiledoc: markdownToMobiledoc('Test Content 1') }; - PostModel.add(newPost, context).then(function (createdPost) { + models.Post.add(newPost, context).then(function (createdPost) { createdPost.get('slug').should.equal('apprehensive-titles-have-too-many-spaces-and-m-dashes-and-also-n-dashes'); Object.keys(eventsTriggered).length.should.eql(1); @@ -1306,7 +1300,7 @@ describe('Post Model', function () { mobiledoc: markdownToMobiledoc('Test Content 1') }; - PostModel.add(newPost, context).then(function (createdPost) { + models.Post.add(newPost, context).then(function (createdPost) { createdPost.get('slug').should.not.equal('rss'); Object.keys(eventsTriggered).length.should.eql(1); @@ -1322,7 +1316,7 @@ describe('Post Model', function () { mobiledoc: markdownToMobiledoc('Test Content 1') }; - PostModel.add(newPost, context).then(function (createdPost) { + models.Post.add(newPost, context).then(function (createdPost) { createdPost.get('slug').should.equal('bhute-dhddkii-bhrvnnaaraa-aahet'); done(); }).catch(done); @@ -1339,7 +1333,7 @@ describe('Post Model', function () { }; // Create the first post - PostModel.add(firstPost, context) + models.Post.add(firstPost, context) .then(function (createdFirstPost) { // Store the slug for later firstPost.slug = createdFirstPost.get('slug'); @@ -1348,7 +1342,7 @@ describe('Post Model', function () { should.exist(eventsTriggered['post.added']); // Create the second post - return PostModel.add(secondPost, context); + return models.Post.add(secondPost, context); }).then(function (createdSecondPost) { // Store the slug for comparison later secondPost.slug = createdSecondPost.get('slug'); @@ -1369,7 +1363,7 @@ describe('Post Model', function () { Object.keys(eventsTriggered).length.should.eql(2); should.exist(eventsTriggered['post.edited']); - return PostModel.findOne({ + return models.Post.findOne({ id: updatedSecondPost.id, status: 'all' }); @@ -1401,7 +1395,7 @@ describe('Post Model', function () { var firstItemData = {id: testUtils.DataGenerator.Content.posts[0].id}; // Test that we have the post we expect, with exactly one tag - PostModel.findOne(firstItemData, {withRelated: ['tags']}).then(function (results) { + models.Post.findOne(firstItemData, {withRelated: ['tags']}).then(function (results) { var post; should.exist(results); post = results.toJSON(); @@ -1422,7 +1416,7 @@ describe('Post Model', function () { should.exist(eventsTriggered['post.deleted']); // Double check we can't find the post again - return PostModel.findOne(firstItemData); + return models.Post.findOne(firstItemData); }).then(function (newResults) { should.equal(newResults, null); @@ -1440,7 +1434,7 @@ describe('Post Model', function () { var firstItemData = {id: testUtils.DataGenerator.Content.posts[3].id, status: 'draft'}; // Test that we have the post we expect, with exactly one tag - PostModel.findOne(firstItemData, {withRelated: ['tags']}).then(function (results) { + models.Post.findOne(firstItemData, {withRelated: ['tags']}).then(function (results) { var post; should.exist(results); post = results.toJSON(); @@ -1459,7 +1453,7 @@ describe('Post Model', function () { should.exist(eventsTriggered['post.deleted']); // Double check we can't find the post again - return PostModel.findOne(firstItemData); + return models.Post.findOne(firstItemData); }).then(function (newResults) { should.equal(newResults, null); @@ -1477,7 +1471,7 @@ describe('Post Model', function () { var firstItemData = {id: testUtils.DataGenerator.Content.posts[5].id}; // Test that we have the post we expect, with exactly one tag - PostModel.findOne(firstItemData, {withRelated: ['tags']}).then(function (results) { + models.Post.findOne(firstItemData, {withRelated: ['tags']}).then(function (results) { var page; should.exist(results); page = results.toJSON(); @@ -1497,7 +1491,7 @@ describe('Post Model', function () { should.exist(eventsTriggered['page.deleted']); // Double check we can't find the post again - return PostModel.findOne(firstItemData); + return models.Post.findOne(firstItemData); }).then(function (newResults) { should.equal(newResults, null); @@ -1515,7 +1509,7 @@ describe('Post Model', function () { var firstItemData = {id: testUtils.DataGenerator.Content.posts[6].id, status: 'draft'}; // Test that we have the post we expect, with exactly one tag - PostModel.findOne(firstItemData, {withRelated: ['tags']}).then(function (results) { + models.Post.findOne(firstItemData, {withRelated: ['tags']}).then(function (results) { var page; should.exist(results); page = results.toJSON(); @@ -1532,7 +1526,7 @@ describe('Post Model', function () { should.exist(eventsTriggered['page.deleted']); // Double check we can't find the post again - return PostModel.findOne(firstItemData); + return models.Post.findOne(firstItemData); }).then(function (newResults) { should.equal(newResults, null); @@ -1550,12 +1544,12 @@ describe('Post Model', function () { it('update post title, but updated_at is out of sync', function (done) { var postToUpdate = {id: testUtils.DataGenerator.Content.posts[1].id}; - PostModel.findOne({id: postToUpdate.id, status: 'all'}) + models.Post.findOne({id: postToUpdate.id, status: 'all'}) .then(function () { return Promise.delay(1000); }) .then(function () { - return PostModel.edit({ + return models.Post.edit({ title: 'New Post Title', updated_at: moment().subtract(1, 'day').format() }, _.extend({}, context, {id: postToUpdate.id})); @@ -1572,12 +1566,12 @@ describe('Post Model', function () { it('update post tags and updated_at is out of sync', function (done) { var postToUpdate = {id: testUtils.DataGenerator.Content.posts[1].id}; - PostModel.findOne({id: postToUpdate.id, status: 'all'}) + models.Post.findOne({id: postToUpdate.id, status: 'all'}) .then(function () { return Promise.delay(1000); }) .then(function () { - return PostModel.edit({ + return models.Post.edit({ tags: [{name: 'new-tag-1'}], updated_at: moment().subtract(1, 'day').format() }, _.extend({}, context, {id: postToUpdate.id})); @@ -1594,12 +1588,12 @@ describe('Post Model', function () { it('update post authors and updated_at is out of sync', function (done) { var postToUpdate = {id: testUtils.DataGenerator.Content.posts[1].id}; - PostModel.findOne({id: postToUpdate.id, status: 'all'}) + models.Post.findOne({id: postToUpdate.id, status: 'all'}) .then(function () { return Promise.delay(1000); }) .then(function () { - return PostModel.edit({ + return models.Post.edit({ authors: [testUtils.DataGenerator.Content.users[3]], updated_at: moment().subtract(1, 'day').format() }, _.extend({}, context, {id: postToUpdate.id})); @@ -1616,12 +1610,12 @@ describe('Post Model', function () { it('update post tags and updated_at is NOT out of sync', function (done) { var postToUpdate = {id: testUtils.DataGenerator.Content.posts[1].id}; - PostModel.findOne({id: postToUpdate.id, status: 'all'}) + models.Post.findOne({id: postToUpdate.id, status: 'all'}) .then(function () { return Promise.delay(1000); }) .then(function () { - return PostModel.edit({ + return models.Post.edit({ tags: [{name: 'new-tag-1'}] }, _.extend({}, context, {id: postToUpdate.id})); }) @@ -1634,12 +1628,12 @@ describe('Post Model', function () { it('update post with no changes, but updated_at is out of sync', function (done) { var postToUpdate = {id: testUtils.DataGenerator.Content.posts[1].id}; - PostModel.findOne({id: postToUpdate.id, status: 'all'}) + models.Post.findOne({id: postToUpdate.id, status: 'all'}) .then(function () { return Promise.delay(1000); }) .then(function () { - return PostModel.edit({ + return models.Post.edit({ updated_at: moment().subtract(1, 'day').format() }, _.extend({}, context, {id: postToUpdate.id})); }) @@ -1655,12 +1649,12 @@ describe('Post Model', function () { title: testUtils.DataGenerator.forModel.posts[1].title }; - PostModel.findOne({id: postToUpdate.id, status: 'all'}) + models.Post.findOne({id: postToUpdate.id, status: 'all'}) .then(function () { return Promise.delay(1000); }) .then(function () { - return PostModel.edit({ + return models.Post.edit({ title: postToUpdate.title, updated_at: moment().subtract(1, 'day').format() }, _.extend({}, context, {id: postToUpdate.id})); @@ -1682,14 +1676,14 @@ describe('Post Model', function () { // We're going to delete all posts by user 1 var authorData = {id: testUtils.DataGenerator.Content.users[0].id}; - PostModel.findAll({context: {internal: true}}).then(function (found) { + models.Post.findAll({context: {internal: true}}).then(function (found) { // There are 50 posts to begin with found.length.should.equal(50); - return PostModel.destroyByAuthor(authorData); + return models.Post.destroyByAuthor(authorData); }).then(function (results) { // User 1 has 10 posts in the database results.length.should.equal(10); - return PostModel.findAll({context: {internal: true}}); + return models.Post.findAll({context: {internal: true}}); }).then(function (found) { // Only 40 should remain found.length.should.equal(40); @@ -1727,10 +1721,10 @@ describe('Post Model', function () { post.status = 'published'; return Promise.props({ - post: PostModel.add(post, _.extend({}, context, {withRelated: ['tags']})), - tag1: TagModel.add(extraTags[0], context), - tag2: TagModel.add(extraTags[1], context), - tag3: TagModel.add(extraTags[2], context) + post: models.Post.add(post, _.extend({}, context, {withRelated: ['tags']})), + tag1: models.Tag.add(extraTags[0], context), + tag2: models.Tag.add(extraTags[1], context), + tag3: models.Tag.add(extraTags[2], context) }).then(function (result) { postJSON = result.post.toJSON({withRelated: ['tags']}); tagJSON.push(result.tag1.toJSON()); @@ -1772,7 +1766,7 @@ describe('Post Model', function () { newJSON.tags = [{id: postJSON.tags[0].id, slug: 'eins'}]; // Edit the post - return PostModel.edit(newJSON, editOptions).then(function (updatedPost) { + return models.Post.edit(newJSON, editOptions).then(function (updatedPost) { updatedPost = updatedPost.toJSON({withRelated: ['tags']}); updatedPost.tags.should.have.lengthOf(1); @@ -1797,7 +1791,7 @@ describe('Post Model', function () { // Edit the post return Promise.delay(1000) .then(function () { - return PostModel.edit(newJSON, editOptions); + return models.Post.edit(newJSON, editOptions); }) .then(function (updatedPost) { updatedPost = updatedPost.toJSON({withRelated: ['tags']}); @@ -1832,7 +1826,7 @@ describe('Post Model', function () { newJSON.tags = [{name: 'tag4'}].concat([newJSON.tags[1]]).concat([newJSON.tags[0]]); // Edit the post - return PostModel.edit(newJSON, editOptions).then(function (updatedPost) { + return models.Post.edit(newJSON, editOptions).then(function (updatedPost) { updatedPost = updatedPost.toJSON({withRelated: ['tags']}); updatedPost.tags.should.have.lengthOf(3); @@ -1862,7 +1856,7 @@ describe('Post Model', function () { newJSON.tags.push({name: 'C#'}); // Edit the post - return PostModel.edit(newJSON, editOptions).then(function (updatedPost) { + return models.Post.edit(newJSON, editOptions).then(function (updatedPost) { updatedPost = updatedPost.toJSON({withRelated: ['tags']}); updatedPost.tags.should.have.lengthOf(3); @@ -1882,7 +1876,7 @@ describe('Post Model', function () { newJSON.tags.push({name: 'tEst'}); // Edit the post - return PostModel.edit(newJSON, editOptions).then(function (updatedPost) { + return models.Post.edit(newJSON, editOptions).then(function (updatedPost) { updatedPost = updatedPost.toJSON({withRelated: ['tags']}); updatedPost.tags.should.have.lengthOf(1); @@ -1892,7 +1886,7 @@ describe('Post Model', function () { // disabling sanitization until we can implement a better version // it('should sanitize the title', function (done) { - // new PostModel().fetch().then(function (model) { + // new models.Post().fetch().then(function (model) { // return model.set({'title': ""}).save(); // }).then(function (saved) { // saved.get('title').should.eql("</title></head><body>[removed]alert('blogtitle');[removed]");