diff --git a/core/test/integration/model/model_posts_spec.js b/core/test/integration/model/model_posts_spec.js index 0c7119ab5d..690695277a 100644 --- a/core/test/integration/model/model_posts_spec.js +++ b/core/test/integration/model/model_posts_spec.js @@ -9,6 +9,8 @@ var should = require('should'), 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, common = require('../../../server/lib/common'), configUtils = require('../../utils/configUtils'), DataGenerator = testUtils.DataGenerator, @@ -51,6 +53,7 @@ describe('Post Model', function () { firstPost.url.should.equal('/html-ipsum/'); firstPost.fields.should.be.an.Array(); firstPost.tags.should.be.an.Array(); + firstPost.author.name.should.equal(DataGenerator.Content.users[0].name); firstPost.fields[0].key.should.equal(DataGenerator.Content.app_fields[0].key); firstPost.created_at.should.be.an.instanceof(Date); @@ -1027,6 +1030,21 @@ describe('Post Model', function () { }); }); + it('[unsupported] can\'t add `author` as object', function () { + var newPost = testUtils.DataGenerator.forModel.posts[2]; + + // `post.author` relation get's ignored in Ghost - unsupported + newPost.author = {id: testUtils.DataGenerator.Content.users[3].id}; + delete newPost.author_id; + + return PostModel.add(newPost, context) + .then(function (createdPost) { + // fallsback to logged in user + createdPost.get('author_id').should.eql(context.context.user); + createdPost.get('author_id').should.not.eql(testUtils.DataGenerator.Content.users[3].id); + }); + }); + it('can add, defaults are all correct', function (done) { var createdPostUpdatedDate, newPost = testUtils.DataGenerator.forModel.posts[2], @@ -1720,6 +1738,8 @@ describe('Post Model', function () { return Promise.props({ post: PostModel.add(post, _.extend({}, context, {withRelated: ['tags']})), + role: RoleModel.add(testUtils.DataGenerator.forKnex.roles[2], context), + user: UserModel.add(testUtils.DataGenerator.forKnex.users[0], context), tag1: TagModel.add(extraTags[0], context), tag2: TagModel.add(extraTags[1], context), tag3: TagModel.add(extraTags[2], context) @@ -1774,6 +1794,22 @@ describe('Post Model', function () { }); }); + it('[unsupported] can\'t edit `author` as object', function () { + var newJSON = _.cloneDeep(postJSON), + modelOptions = _.clone(editOptions); + + newJSON.author.should.eql(testUtils.DataGenerator.Content.users[0].id); + newJSON.author = {id: testUtils.DataGenerator.Content.users[3].id}; + delete newJSON.author_id; + + modelOptions.withRelated.push('author'); + return PostModel.edit(newJSON, modelOptions) + .then(function (updatedPost) { + updatedPost.get('author_id').should.eql(testUtils.DataGenerator.Content.users[0].id); + updatedPost.related('author').toJSON().slug.should.eql(testUtils.DataGenerator.Content.users[0].slug); + }); + }); + it('can\'t edit dates and authors of existing tag', function () { var newJSON = _.cloneDeep(postJSON), updatedAtFormat;