0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

fix for page deletion not updating sitemap-page.xml

closes #5913

Sitemap deletion is based on the page.unpublished event. The previous
logic was always sending post.unpublished instead. If page or post
event is triggered is based on the ‘page’ attribute of the model. When
the destroyed handler all attributes are already cleared from the model
which makes this logic always fall back to post.

The fix is to move to the destroying event which still has all the
model values in place.
This commit is contained in:
Oliver Schneider 2015-10-12 09:26:26 +02:00
parent b6c7d14359
commit 13adaec6e7
2 changed files with 74 additions and 1 deletions

View file

@ -104,7 +104,7 @@ Post = ghostBookshelf.Model.extend({
}
});
this.on('destroyed', function onDestroyed(model) {
this.on('destroying', function onDestroying(model) {
if (model.previous('status') === 'published') {
model.emitChange('unpublished');
}

View file

@ -886,6 +886,79 @@ describe('Post Model', function () {
done();
}).catch(done);
});
it('published page', function (done) {
// We're going to try deleting page id 6 which also has tag id 1
var firstItemData = {id: 6};
// Test that we have the post we expect, with exactly one tag
PostModel.findOne(firstItemData, {include: ['tags']}).then(function (results) {
var page;
should.exist(results);
page = results.toJSON();
page.id.should.equal(firstItemData.id);
page.status.should.equal('published');
page.page.should.be.true;
// Destroy the page
return PostModel.destroy(firstItemData);
}).then(function (response) {
var deleted = response.toJSON();
should.equal(deleted.author, undefined);
eventSpy.calledTwice.should.be.true;
eventSpy.firstCall.calledWith('page.unpublished').should.be.true;
eventSpy.secondCall.calledWith('page.deleted').should.be.true;
// Double check we can't find the post again
return PostModel.findOne(firstItemData);
}).then(function (newResults) {
should.equal(newResults, null);
// Double check we can't find any related tags
return ghostBookshelf.knex.select().table('posts_tags').where('post_id', firstItemData.id);
}).then(function (postsTags) {
postsTags.should.be.empty;
done();
}).catch(done);
});
it('draft page', function (done) {
// We're going to try deleting post id 4 which also has tag id 4
var firstItemData = {id: 7, status: 'draft'};
// Test that we have the post we expect, with exactly one tag
PostModel.findOne(firstItemData, {include: ['tags']}).then(function (results) {
var page;
should.exist(results);
page = results.toJSON();
page.id.should.equal(firstItemData.id);
// Destroy the page
return PostModel.destroy(firstItemData);
}).then(function (response) {
var deleted = response.toJSON();
should.equal(deleted.author, undefined);
eventSpy.calledOnce.should.be.true;
eventSpy.firstCall.calledWith('page.deleted').should.be.true;
// Double check we can't find the post again
return PostModel.findOne(firstItemData);
}).then(function (newResults) {
should.equal(newResults, null);
// Double check we can't find any related tags
return ghostBookshelf.knex.select().table('posts_tags').where('post_id', firstItemData.id);
}).then(function (postsTags) {
postsTags.should.be.empty;
done();
}).catch(done);
});
});
});