mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Merge pull request #720 from skattyadz/issue-658
Fix bug preventing tags from being saved when a Post is created.
This commit is contained in:
commit
dd7e04e9a5
2 changed files with 26 additions and 3 deletions
|
@ -140,17 +140,20 @@ Post = GhostBookshelf.Model.extend({
|
||||||
return checkIfSlugExists(slug);
|
return checkIfSlugExists(slug);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateTags: function () {
|
updateTags: function (newTags) {
|
||||||
var self = this,
|
var self = this,
|
||||||
tagOperations = [],
|
tagOperations = [],
|
||||||
newTags = this.get('tags'),
|
|
||||||
tagsToDetach,
|
tagsToDetach,
|
||||||
existingTagIDs,
|
existingTagIDs,
|
||||||
tagsToCreateAndAdd,
|
tagsToCreateAndAdd,
|
||||||
tagsToAddByID,
|
tagsToAddByID,
|
||||||
fetchOperation;
|
fetchOperation;
|
||||||
|
|
||||||
if (!newTags) {
|
if (newTags === this) {
|
||||||
|
newTags = this.get('tags');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!newTags || !this.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,6 +374,13 @@ Post = GhostBookshelf.Model.extend({
|
||||||
|
|
||||||
// Otherwise, you shall not pass.
|
// Otherwise, you shall not pass.
|
||||||
return when.reject();
|
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();
|
done();
|
||||||
}).then(null, 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…
Add table
Reference in a new issue