mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-11 00:37:55 +03:00
Fix bug preventing tags from being saved when a Post is created.
Fixes #658
This commit is contained in:
parent
c82ebb15d8
commit
f6b86a98ff
@ -140,17 +140,20 @@ Post = GhostBookshelf.Model.extend({
|
||||
return checkIfSlugExists(slug);
|
||||
},
|
||||
|
||||
updateTags: function () {
|
||||
updateTags: function (newTags) {
|
||||
var self = this,
|
||||
tagOperations = [],
|
||||
newTags = this.get('tags'),
|
||||
tagsToDetach,
|
||||
existingTagIDs,
|
||||
tagsToCreateAndAdd,
|
||||
tagsToAddByID,
|
||||
fetchOperation;
|
||||
|
||||
if (!newTags) {
|
||||
if (newTags === this) {
|
||||
newTags = this.get('tags');
|
||||
}
|
||||
|
||||
if (!newTags || !this.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -371,6 +374,13 @@ Post = GhostBookshelf.Model.extend({
|
||||
|
||||
// Otherwise, you shall not pass.
|
||||
return when.reject();
|
||||
},
|
||||
|
||||
add: function (newPostData, options) {
|
||||
return GhostBookshelf.Model.add.call(this, newPostData, options).tap(function (post) {
|
||||
// associated models can't be created until the post has an ID, so run this after
|
||||
return post.updateTags(newPostData.tags);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -207,6 +207,19 @@ describe('Tag Model', function () {
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
|
||||
|
||||
it('can add a tag to a post on creation', function (done) {
|
||||
var newPost = {title: 'Test Title 1', content_raw: 'Test Content 1', tags: ['test_tag_1']};
|
||||
|
||||
PostModel.add(newPost).then(function (createdPost) {
|
||||
return PostModel.read({id: createdPost.id}, { withRelated: ['tags']});
|
||||
}).then(function (postWithTag) {
|
||||
postWithTag.related('tags').length.should.equal(1);
|
||||
done();
|
||||
}).then(null, done);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user