0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

🐛 Fixed plaintext field not being cleared when post body is removed

closes https://github.com/TryGhost/Ghost/issues/10557
- add conditional for plaintext changing rather than only being present for when to set a new plaintext value
This commit is contained in:
Kevin Ansfield 2019-03-04 14:03:44 +00:00
parent d7238e94c2
commit 2b34327544
2 changed files with 28 additions and 1 deletions

View file

@ -368,7 +368,7 @@ Post = ghostBookshelf.Model.extend({
// CASE: html is e.g. <p></p>
// @NOTE: Otherwise we will always update the resource to `plaintext: ''` and Bookshelf thinks that this
// value was modified.
if (plaintext) {
if (plaintext || plaintext !== this.get('plaintext')) {
this.set('plaintext', plaintext);
}
}

View file

@ -507,6 +507,33 @@ describe('Post Model', function () {
}).catch(done);
});
it('converts html to plaintext if html is null', function (done) {
var postId = testUtils.DataGenerator.Content.posts[0].id;
models.Post.findOne({id: postId}).then(function (results) {
should.exist(results);
results.attributes.html.should.match(/HTML Ipsum Presents/);
should.exist(results.attributes.plaintext);
return models.Post.edit({updated_at: results.attributes.updated_at}, _.extend({}, context, {id: postId}));
}).then(function (edited) {
should.exist(edited);
edited.attributes.html.should.match(/HTML Ipsum Presents/);
edited.attributes.plaintext.should.match(/HTML Ipsum Presents/);
return edited;
}).then(function (edited) {
return models.Post.edit({
mobiledoc: DataGenerator.markdownToMobiledoc(''),
updated_at: edited.attributes.updated_at
}, _.extend({}, context, {id: postId}));
}).then(function (edited) {
should.exist(edited);
should.not.exist(edited.attributes.html);
should.not.exist(edited.attributes.plaintext);
done();
}).catch(done);
});
it('can publish draft post', function (done) {
var postId = testUtils.DataGenerator.Content.posts[3].id;