mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36: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:
parent
dbd7060e69
commit
2e8a8ad88a
2 changed files with 33 additions and 3 deletions
|
@ -12,6 +12,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var config = require('../../config'),
|
var config = require('../../config'),
|
||||||
|
labs = require('../../utils/labs'),
|
||||||
|
|
||||||
// Context patterns, should eventually come from Channel configuration
|
// Context patterns, should eventually come from Channel configuration
|
||||||
privatePattern = new RegExp('^\\/' + config.get('routeKeywords').private + '\\/'),
|
privatePattern = new RegExp('^\\/' + config.get('routeKeywords').private + '\\/'),
|
||||||
|
@ -56,7 +57,7 @@ function setResponseContext(req, res, data) {
|
||||||
res.locals.context.push(req.channelConfig.name);
|
res.locals.context.push(req.channelConfig.name);
|
||||||
} else if (privatePattern.test(res.locals.relativeUrl)) {
|
} else if (privatePattern.test(res.locals.relativeUrl)) {
|
||||||
res.locals.context.push('private');
|
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');
|
res.locals.context.push('subscribe');
|
||||||
} else if (data && data.post && data.post.page) {
|
} else if (data && data.post && data.post.page) {
|
||||||
res.locals.context.push('page');
|
res.locals.context.push('page');
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
var should = require('should'),
|
var should = require('should'),
|
||||||
|
sinon = require('sinon'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
|
|
||||||
// Stuff we are testing
|
// Stuff we are testing
|
||||||
channelConfig = require('../../../../server/controllers/frontend/channel-config'),
|
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 () {
|
describe('Contexts', function () {
|
||||||
var req, res, data, setupContext;
|
var req, res, data, setupContext;
|
||||||
|
@ -19,6 +23,10 @@ describe('Contexts', function () {
|
||||||
data = {};
|
data = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A context is created based on the URL, and the channel config if we're rendering
|
* A context is created based on the URL, and the channel config if we're rendering
|
||||||
* any part of a channel
|
* any part of a channel
|
||||||
|
@ -352,9 +360,13 @@ describe('Contexts', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Subscribe', 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
|
// Setup test
|
||||||
|
sandbox.stub(labs, 'isSet').returns(true);
|
||||||
setupContext('/subscribe/');
|
setupContext('/subscribe/');
|
||||||
|
data.post = {
|
||||||
|
page: false
|
||||||
|
};
|
||||||
|
|
||||||
// Execute test
|
// Execute test
|
||||||
setResponseContext(req, res, data);
|
setResponseContext(req, res, data);
|
||||||
|
@ -364,6 +376,23 @@ describe('Contexts', function () {
|
||||||
res.locals.context.should.be.an.Array().with.lengthOf(1);
|
res.locals.context.should.be.an.Array().with.lengthOf(1);
|
||||||
res.locals.context[0].should.eql('subscribe');
|
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 () {
|
describe('RSS', function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue