mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Replace missing title with "(Untitled)" when creating a post
closes #6014 - replace missing title with "(Untitled)" when creating a post - add a test for creating post without title
This commit is contained in:
parent
6a0c162d99
commit
0a0aaf01b2
2 changed files with 14 additions and 1 deletions
|
@ -115,6 +115,7 @@ Post = ghostBookshelf.Model.extend({
|
|||
saving: function saving(model, attr, options) {
|
||||
var self = this,
|
||||
tagsToCheck,
|
||||
title,
|
||||
i;
|
||||
|
||||
options = options || {};
|
||||
|
@ -138,7 +139,8 @@ Post = ghostBookshelf.Model.extend({
|
|||
|
||||
// disabling sanitization until we can implement a better version
|
||||
// this.set('title', this.sanitize('title').trim());
|
||||
this.set('title', this.get('title').trim());
|
||||
title = this.get('title') || '(Untitled)';
|
||||
this.set('title', title.trim());
|
||||
|
||||
// ### Business logic for published_at and published_by
|
||||
// If the current status is 'published' and published_at is not set, set it to now
|
||||
|
|
|
@ -653,6 +653,17 @@ describe('Post Model', function () {
|
|||
}).catch(done);
|
||||
});
|
||||
|
||||
it('can add default title, if it\'s missing', function (done) {
|
||||
PostModel.add({
|
||||
markdown: 'Content'
|
||||
}, context).then(function (newPost) {
|
||||
should.exist(newPost);
|
||||
newPost.get('title').should.equal('(Untitled)');
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('can trim title', function (done) {
|
||||
var untrimmedCreateTitle = ' test trimmed create title ',
|
||||
untrimmedUpdateTitle = ' test trimmed update title ',
|
||||
|
|
Loading…
Add table
Reference in a new issue