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

🐛 Fixed meta on subscribe page if labs not enabled (#8848)

refs #8597

- Only set the subscribe context if the labs flag is set
- Committed at 38000ft
This commit is contained in:
Hannah Wolfe 2017-08-08 08:45:37 +01:00 committed by Katharina Irrgang
parent dbd7060e69
commit 2e8a8ad88a
2 changed files with 33 additions and 3 deletions

View file

@ -12,6 +12,7 @@
*/
var config = require('../../config'),
labs = require('../../utils/labs'),
// Context patterns, should eventually come from Channel configuration
privatePattern = new RegExp('^\\/' + config.get('routeKeywords').private + '\\/'),
@ -56,7 +57,7 @@ function setResponseContext(req, res, data) {
res.locals.context.push(req.channelConfig.name);
} else if (privatePattern.test(res.locals.relativeUrl)) {
res.locals.context.push('private');
} else if (subscribePattern.test(res.locals.relativeUrl)) {
} else if (subscribePattern.test(res.locals.relativeUrl) && labs.isSet('subscribers') === true) {
res.locals.context.push('subscribe');
} else if (data && data.post && data.post.page) {
res.locals.context.push('page');

View file

@ -1,9 +1,13 @@
var should = require('should'),
sinon = require('sinon'),
_ = require('lodash'),
// Stuff we are testing
channelConfig = require('../../../../server/controllers/frontend/channel-config'),
setResponseContext = require('../../../../server/controllers/frontend/context');
setResponseContext = require('../../../../server/controllers/frontend/context'),
labs = require('../../../../server/utils/labs'),
sandbox = sinon.sandbox.create();
describe('Contexts', function () {
var req, res, data, setupContext;
@ -19,6 +23,10 @@ describe('Contexts', function () {
data = {};
});
afterEach(function () {
sandbox.restore();
});
/**
* A context is created based on the URL, and the channel config if we're rendering
* any part of a channel
@ -352,9 +360,13 @@ describe('Contexts', function () {
});
describe('Subscribe', function () {
it('should correctly identify /subscribe/ as the subscribe route', function () {
it('should identify /subscribe/ as the subscribe route if labs flag set', function () {
// Setup test
sandbox.stub(labs, 'isSet').returns(true);
setupContext('/subscribe/');
data.post = {
page: false
};
// Execute test
setResponseContext(req, res, data);
@ -364,6 +376,23 @@ describe('Contexts', function () {
res.locals.context.should.be.an.Array().with.lengthOf(1);
res.locals.context[0].should.eql('subscribe');
});
it('should not identify /subscribe/ as subscribe route if labs flag NOT set', function () {
// Setup test
sandbox.stub(labs, 'isSet').returns(false);
setupContext('/subscribe/');
data.post = {
page: false
};
// Execute test
setResponseContext(req, res, data);
// Check context
should.exist(res.locals.context);
res.locals.context.should.be.an.Array().with.lengthOf(1);
res.locals.context[0].should.eql('post');
});
});
describe('RSS', function () {