Skip to content

Commit

Permalink
Sitemaps correctly filter draft posts
Browse files Browse the repository at this point in the history
fixes #4612

- adds missing line of code to remove draft posts
- adds tests to check drafts aren't added
  • Loading branch information
ErisDS committed Dec 9, 2014
1 parent 93c5ff3 commit 2ef77d6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/server/data/sitemap/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ _.extend(SiteMapManager.prototype, {
return;
}

if (post.get('status') !== 'published') {
return;
}

this.posts.addUrl(post.toJSON());
},

Expand Down
37 changes: 37 additions & 0 deletions core/test/integration/sitemap_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ describe('Sitemap', function () {
}).catch(done);
});

it('doesn\'t add draft pages', function (done) {
var manager = makeStubManager(),
fake = {
toJSON: sandbox.stub().returns({
status: 'draft'
}),
get: sandbox.stub().returns('draft'),
updated: sandbox.stub().returns('draft')
};

manager.init().then(function () {
manager.pageAdded(fake);

manager.pages.addUrl.called.should.equal(false);

done();
}).catch(done);
});

it('deletes pages that were unpublished', function (done) {
var manager = makeStubManager(),
fake = {
Expand Down Expand Up @@ -225,6 +244,24 @@ describe('Sitemap', function () {
}).catch(done);
});

it('doesn\'t add draft posts', function (done) {
var manager = makeStubManager(),
fake = {
toJSON: sandbox.stub().returns({
status: 'draft'
}),
get: sandbox.stub().returns('draft'),
updated: sandbox.stub().returns('draft')
};

manager.init().then(function () {
manager.postAdded(fake);
manager.posts.addUrl.called.should.equal(false);

done();
}).catch(done);
});

it('deletes posts that were unpublished', function (done) {
var manager = makeStubManager(),
fake = {
Expand Down

0 comments on commit 2ef77d6

Please sign in to comment.