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

🐛 Fixed incorrect body class output on page (#11264)

closes #11262
refs #10042

- Fixed issue where using {{body_class}} helper on a "page" type of a page was outputting `post-template` instead of `page-template`
- The issue was caused by this change 7dc38e2078 (diff-c33149d31de747bc5fbefcaf7a44da79L67-L72)
- Updated the comment to have real context of why this if is here
- Added test coverage for .page-template class
This commit is contained in:
Naz Gargol 2019-10-23 18:06:45 +02:00 committed by GitHub
parent f4cadc0709
commit 518f2ccd82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 20 deletions

View file

@ -55,7 +55,13 @@ function setResponseContext(req, res, data) {
}
}
if (data && data.post) {
// @TODO: remove first if condition when only page key is returned
// ref.: https://github.com/TryGhost/Ghost/issues/10042
if (data && data.post && data.post.page) {
if (!res.locals.context.includes('page')) {
res.locals.context.push('page');
}
} else if (data && data.post) {
if (!res.locals.context.includes('post')) {
res.locals.context.push('post');
}

View file

@ -123,35 +123,23 @@ describe('Frontend Routing', function () {
.end(doEnd(done));
});
it('should respond with html for valid url', function (done) {
it('should respond with html for valid post url', function (done) {
request.get('/welcome/')
.expect('Content-Type', /html/)
.expect('Cache-Control', testUtils.cacheRules.public)
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
var $ = cheerio.load(res.text);
should.not.exist(res.headers['x-cache-invalidate']);
should.not.exist(res.headers['X-CSRF-Token']);
should.not.exist(res.headers['set-cookie']);
should.exist(res.headers.date);
// NOTE: This is the title from the settings.
$('title').text().should.equal('Welcome to Ghost');
// @TODO: change or remove?
// $('.content .post').length.should.equal(1);
// $('.poweredby').text().should.equal('Proudly published with Ghost');
// $('body.post-template').length.should.equal(1);
// $('body.tag-getting-started').length.should.equal(1);
// $('article.post').length.should.equal(1);
// $('article.tag-getting-started').length.should.equal(1);
$('body.post-template').length.should.equal(1);
$('body.tag-getting-started').length.should.equal(1);
$('article.post').length.should.equal(2);
$('article.tag-getting-started').length.should.equal(2);
done();
doEnd(done)(err, res);
});
});
@ -355,7 +343,20 @@ describe('Frontend Routing', function () {
.expect('Content-Type', /html/)
.expect('Cache-Control', testUtils.cacheRules.public)
.expect(200)
.end(doEnd(done));
.end(function (err, res) {
var $ = cheerio.load(res.text);
should.not.exist(res.headers['x-cache-invalidate']);
should.not.exist(res.headers['X-CSRF-Token']);
should.not.exist(res.headers['set-cookie']);
should.exist(res.headers.date);
$('title').text().should.equal('Ghost');
$('body.page-template').length.should.equal(1);
$('article.post').length.should.equal(1);
doEnd(done)(err, res);
});
});
it('should redirect without slash', function (done) {