mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Subscribers: Adding subscribe context
- ensure that the `/subscribe/` route gets a context set correctly - update context tests§
This commit is contained in:
parent
e6fe1c672c
commit
d245f875bf
2 changed files with 18 additions and 0 deletions
|
@ -15,6 +15,7 @@ var config = require('../../config'),
|
|||
|
||||
// Context patterns, should eventually come from Channel configuration
|
||||
privatePattern = new RegExp('^\\/' + config.routeKeywords.private + '\\/'),
|
||||
subscribePattern = new RegExp('^\\/' + config.routeKeywords.subscribe + '\\/'),
|
||||
rssPattern = new RegExp('^\\/rss\\/'),
|
||||
homePattern = new RegExp('^\\/$');
|
||||
|
||||
|
@ -49,6 +50,8 @@ 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)) {
|
||||
res.locals.context.push('subscribe');
|
||||
} else if (data && data.post && data.post.page) {
|
||||
res.locals.context.push('page');
|
||||
} else if (data && data.post) {
|
||||
|
|
|
@ -351,6 +351,21 @@ describe('Contexts', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Subscribe', function () {
|
||||
it('should correctly identify /subscribe/ as the subscribe route', function () {
|
||||
// Setup test
|
||||
setupContext('/subscribe/');
|
||||
|
||||
// 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('subscribe');
|
||||
});
|
||||
});
|
||||
|
||||
describe('RSS', function () {
|
||||
// NOTE: this works, but is never used in reality, as setResponseContext isn't called
|
||||
// for RSS feeds at the moment.
|
||||
|
|
Loading…
Add table
Reference in a new issue