mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03:00
Removed use of filters module
no-issue As we're deprecating apps, filters are no longer used. - Removed use of filters in helpers - Removed use of filters from routing service - Removed use of filters from rss service - Removed use of filters in base model
This commit is contained in:
parent
54ac98037b
commit
90c2dbcd6b
@ -5,7 +5,6 @@
|
||||
var proxy = require('./proxy'),
|
||||
_ = require('lodash'),
|
||||
SafeString = proxy.SafeString,
|
||||
filters = proxy.filters,
|
||||
settingsCache = proxy.settingsCache;
|
||||
|
||||
// We use the name ghost_foot to match the helper for consistency:
|
||||
@ -22,9 +21,5 @@ module.exports = function ghost_foot(options) { // eslint-disable-line camelcase
|
||||
foot.push(postCodeinjection);
|
||||
}
|
||||
|
||||
return filters
|
||||
.doFilter('ghost_foot', foot)
|
||||
.then(function (foot) {
|
||||
return new SafeString(foot.join(' ').trim());
|
||||
});
|
||||
return new SafeString(foot.join(' ').trim());
|
||||
};
|
||||
|
@ -10,7 +10,6 @@ var proxy = require('./proxy'),
|
||||
getAssetUrl = proxy.metaData.getAssetUrl,
|
||||
escapeExpression = proxy.escapeExpression,
|
||||
SafeString = proxy.SafeString,
|
||||
filters = proxy.filters,
|
||||
logging = proxy.logging,
|
||||
settingsCache = proxy.settingsCache,
|
||||
config = proxy.config,
|
||||
@ -191,9 +190,6 @@ module.exports = function ghost_head(options) { // eslint-disable-line camelcase
|
||||
head.push(postCodeInjection);
|
||||
}
|
||||
}
|
||||
return filters.doFilter('ghost_head', head);
|
||||
})
|
||||
.then(function afterFilters(head) {
|
||||
debug('end');
|
||||
return new SafeString(head.join('\n ').trim());
|
||||
})
|
||||
|
@ -48,6 +48,7 @@ registerAllCoreHelpers = function registerAllCoreHelpers() {
|
||||
registerThemeHelper('encode', coreHelpers.encode);
|
||||
registerThemeHelper('excerpt', coreHelpers.excerpt);
|
||||
registerThemeHelper('foreach', coreHelpers.foreach);
|
||||
registerThemeHelper('ghost_foot', coreHelpers.ghost_foot);
|
||||
registerThemeHelper('has', coreHelpers.has);
|
||||
registerThemeHelper('is', coreHelpers.is);
|
||||
registerThemeHelper('img_url', coreHelpers.img_url);
|
||||
@ -68,7 +69,6 @@ registerAllCoreHelpers = function registerAllCoreHelpers() {
|
||||
registerThemeHelper('url', coreHelpers.url);
|
||||
|
||||
// Async theme helpers
|
||||
registerAsyncThemeHelper('ghost_foot', coreHelpers.ghost_foot);
|
||||
registerAsyncThemeHelper('ghost_head', coreHelpers.ghost_head);
|
||||
registerAsyncThemeHelper('next_post', coreHelpers.next_post);
|
||||
registerAsyncThemeHelper('prev_post', coreHelpers.prev_post);
|
||||
|
@ -43,9 +43,6 @@ module.exports = {
|
||||
// Labs utils for enabling/disabling helpers
|
||||
labs: require('../services/labs'),
|
||||
|
||||
// System for apps to hook into one day maybe
|
||||
filters: require('../filters'),
|
||||
|
||||
// Things required from data/meta
|
||||
metaData: {
|
||||
get: require('../data/meta'), // ghost_head
|
||||
|
@ -15,7 +15,6 @@ const _ = require('lodash'),
|
||||
db = require('../../data/db'),
|
||||
common = require('../../lib/common'),
|
||||
security = require('../../lib/security'),
|
||||
filters = require('../../filters'),
|
||||
schema = require('../../data/schema'),
|
||||
urlService = require('../../services/url'),
|
||||
validation = require('../../data/validation'),
|
||||
@ -1118,20 +1117,17 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||
}
|
||||
}
|
||||
|
||||
// Check the filtered slug doesn't match any of the reserved keywords
|
||||
return filters.doFilter('slug.reservedSlugs', config.get('slugs').reserved).then(function then(slugList) {
|
||||
// Some keywords cannot be changed
|
||||
slugList = _.union(slugList, urlService.utils.getProtectedSlugs());
|
||||
// Some keywords cannot be changed
|
||||
const slugList = _.union(config.get('slugs').reserved, urlService.utils.getProtectedSlugs());
|
||||
slug = _.includes(slugList, slug) ? slug + '-' + baseName : slug;
|
||||
|
||||
return _.includes(slugList, slug) ? slug + '-' + baseName : slug;
|
||||
}).then(function then(slug) {
|
||||
// if slug is empty after trimming use the model name
|
||||
if (!slug) {
|
||||
slug = baseName;
|
||||
}
|
||||
// Test for duplicate slugs.
|
||||
return checkIfSlugExists(slug);
|
||||
});
|
||||
// if slug is empty after trimming use the model name
|
||||
if (!slug) {
|
||||
slug = baseName;
|
||||
}
|
||||
|
||||
// Test for duplicate slugs.
|
||||
return checkIfSlugExists(slug);
|
||||
},
|
||||
|
||||
parseOrderOption: function (order, withRelated) {
|
||||
|
@ -3,7 +3,6 @@ const _ = require('lodash'),
|
||||
common = require('../../../lib/common'),
|
||||
security = require('../../../lib/security'),
|
||||
themes = require('../../themes'),
|
||||
filters = require('../../../filters'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
// @TODO: the collection+rss controller does almost the same
|
||||
@ -56,13 +55,8 @@ module.exports = function channelController(req, res, next) {
|
||||
helpers.secure(req, data);
|
||||
});
|
||||
|
||||
// @TODO: properly design these filters
|
||||
filters.doFilter('prePostsRender', result.posts, res.locals)
|
||||
.then(function (posts) {
|
||||
result.posts = posts;
|
||||
return result;
|
||||
})
|
||||
.then(helpers.renderEntries(req, res));
|
||||
const renderer = helpers.renderEntries(req, res);
|
||||
return renderer(result);
|
||||
})
|
||||
.catch(helpers.handleError(next));
|
||||
};
|
||||
|
@ -4,7 +4,6 @@ const _ = require('lodash'),
|
||||
security = require('../../../lib/security'),
|
||||
urlService = require('../../../services/url'),
|
||||
themes = require('../../themes'),
|
||||
filters = require('../../../filters'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
module.exports = function collectionController(req, res, next) {
|
||||
@ -67,13 +66,8 @@ module.exports = function collectionController(req, res, next) {
|
||||
helpers.secure(req, data);
|
||||
});
|
||||
|
||||
// @TODO: properly design these filters
|
||||
filters.doFilter('prePostsRender', result.posts, res.locals)
|
||||
.then(function (posts) {
|
||||
result.posts = posts;
|
||||
return result;
|
||||
})
|
||||
.then(helpers.renderEntries(req, res));
|
||||
const renderer = helpers.renderEntries(req, res);
|
||||
return renderer(result);
|
||||
})
|
||||
.catch(helpers.handleError(next));
|
||||
};
|
||||
|
@ -1,7 +1,6 @@
|
||||
const debug = require('ghost-ignition').debug('services:routing:controllers:entry'),
|
||||
url = require('url'),
|
||||
urlService = require('../../url'),
|
||||
filters = require('../../../filters'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
/**
|
||||
@ -81,8 +80,8 @@ module.exports = function entryController(req, res, next) {
|
||||
|
||||
helpers.secure(req, entry);
|
||||
|
||||
filters.doFilter('prePostsRender', entry, res.locals)
|
||||
.then(helpers.renderEntry(req, res));
|
||||
const renderer = helpers.renderEntry(req, res);
|
||||
return renderer(entry);
|
||||
})
|
||||
.catch(helpers.handleError(next));
|
||||
};
|
||||
|
@ -1,6 +1,5 @@
|
||||
const debug = require('ghost-ignition').debug('services:routing:controllers:preview'),
|
||||
urlService = require('../../url'),
|
||||
filters = require('../../../filters'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
module.exports = function previewController(req, res, next) {
|
||||
@ -14,7 +13,7 @@ module.exports = function previewController(req, res, next) {
|
||||
include: 'author,authors,tags'
|
||||
};
|
||||
|
||||
api[res.routerOptions.query.controller]
|
||||
return api[res.routerOptions.query.controller]
|
||||
.read(params)
|
||||
.then(function then(result) {
|
||||
const post = result[res.routerOptions.query.resource][0];
|
||||
@ -41,8 +40,8 @@ module.exports = function previewController(req, res, next) {
|
||||
|
||||
helpers.secure(req, post);
|
||||
|
||||
filters.doFilter('prePostsRender', post, res.locals)
|
||||
.then(helpers.renderEntry(req, res));
|
||||
const renderer = helpers.renderEntry(req, res);
|
||||
return renderer(post);
|
||||
})
|
||||
.catch(helpers.handleError(next));
|
||||
};
|
||||
|
@ -2,7 +2,6 @@ var downsize = require('downsize'),
|
||||
Promise = require('bluebird'),
|
||||
RSS = require('rss'),
|
||||
urlService = require('../../services/url'),
|
||||
filters = require('../../filters'),
|
||||
generateFeed,
|
||||
generateItem,
|
||||
generateTags;
|
||||
@ -90,14 +89,10 @@ generateFeed = function generateFeed(baseUrl, data) {
|
||||
return data.posts.reduce((feedPromise, post) => {
|
||||
return feedPromise.then(() => {
|
||||
const item = generateItem(post, siteUrl, data.secure);
|
||||
return filters.doFilter('rss.item', item, post).then((item) => {
|
||||
return feed.item(item);
|
||||
});
|
||||
return feed.item(item);
|
||||
});
|
||||
}, Promise.resolve()).then(() => {
|
||||
return filters.doFilter('rss.feed', feed).then((feed) => {
|
||||
return feed.xml();
|
||||
});
|
||||
return feed.xml();
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -15,21 +15,18 @@ describe('{{ghost_foot}} helper', function () {
|
||||
settingsCacheStub = sinon.stub(settingsCache, 'get');
|
||||
});
|
||||
|
||||
it('outputs global injected code', function (done) {
|
||||
it('outputs global injected code', function () {
|
||||
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
||||
|
||||
helpers.ghost_foot({data: {}}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
const rendered = helpers.ghost_foot({data: {}});
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
||||
});
|
||||
|
||||
it('outputs post injected code', function (done) {
|
||||
it('outputs post injected code', function () {
|
||||
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
||||
|
||||
helpers.ghost_foot({
|
||||
const rendered = helpers.ghost_foot({
|
||||
data: {
|
||||
root: {
|
||||
post: {
|
||||
@ -37,19 +34,16 @@ describe('{{ghost_foot}} helper', function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
||||
rendered.string.should.match(/post-codeinjection/);
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
||||
rendered.string.should.match(/post-codeinjection/);
|
||||
});
|
||||
|
||||
it('handles post injected code being null', function (done) {
|
||||
it('handles post injected code being null', function () {
|
||||
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
||||
|
||||
helpers.ghost_foot({
|
||||
const rendered = helpers.ghost_foot({
|
||||
data: {
|
||||
root: {
|
||||
post: {
|
||||
@ -57,19 +51,16 @@ describe('{{ghost_foot}} helper', function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
||||
rendered.string.should.not.match(/post-codeinjection/);
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
||||
rendered.string.should.not.match(/post-codeinjection/);
|
||||
});
|
||||
|
||||
it('handles post injected code being empty', function (done) {
|
||||
it('handles post injected code being empty', function () {
|
||||
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
||||
|
||||
helpers.ghost_foot({
|
||||
const rendered = helpers.ghost_foot({
|
||||
data: {
|
||||
root: {
|
||||
post: {
|
||||
@ -77,34 +68,25 @@ describe('{{ghost_foot}} helper', function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
||||
rendered.string.should.not.match(/post-codeinjection/);
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
||||
rendered.string.should.not.match(/post-codeinjection/);
|
||||
});
|
||||
|
||||
it('handles global empty code injection', function (done) {
|
||||
it('handles global empty code injection', function () {
|
||||
settingsCacheStub.withArgs('ghost_foot').returns('');
|
||||
|
||||
helpers.ghost_foot({data: {}}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.eql('');
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
const rendered = helpers.ghost_foot({data: {}});
|
||||
should.exist(rendered);
|
||||
rendered.string.should.eql('');
|
||||
});
|
||||
|
||||
it('handles global undefined code injection', function (done) {
|
||||
it('handles global undefined code injection', function () {
|
||||
settingsCacheStub.withArgs('ghost_foot').returns(undefined);
|
||||
|
||||
helpers.ghost_foot({data: {}}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.eql('');
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
const rendered = helpers.ghost_foot({data: {}});
|
||||
should.exist(rendered);
|
||||
rendered.string.should.eql('');
|
||||
});
|
||||
});
|
||||
|
@ -6,7 +6,6 @@ var should = require('should'),
|
||||
models = require('../../../../server/models'),
|
||||
common = require('../../../../server/lib/common'),
|
||||
urlService = require('../../../../server/services/url'),
|
||||
filters = require('../../../../server/filters'),
|
||||
testUtils = require('../../../utils');
|
||||
|
||||
describe('Models: base', function () {
|
||||
@ -24,7 +23,6 @@ describe('Models: base', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
sinon.stub(security.string, 'safe');
|
||||
sinon.stub(filters, 'doFilter').resolves();
|
||||
sinon.stub(urlService.utils, 'getProtectedSlugs').returns(['upsi', 'schwupsi']);
|
||||
|
||||
Model = sinon.stub();
|
||||
|
@ -3,7 +3,6 @@ const should = require('should'),
|
||||
testUtils = require('../../../../utils'),
|
||||
common = require('../../../../../server/lib/common'),
|
||||
security = require('../../../../../server/lib/security'),
|
||||
filters = require('../../../../../server/filters'),
|
||||
themeService = require('../../../../../server/services/themes'),
|
||||
controllers = require('../../../../../server/services/routing/controllers'),
|
||||
helpers = require('../../../../../server/services/routing/helpers');
|
||||
@ -47,11 +46,7 @@ describe('Unit - services/routing/controllers/channel', function () {
|
||||
}
|
||||
});
|
||||
|
||||
sinon.stub(helpers, 'renderEntries').get(function () {
|
||||
return renderStub;
|
||||
});
|
||||
|
||||
sinon.stub(filters, 'doFilter');
|
||||
sinon.stub(helpers, 'renderEntries').returns(renderStub);
|
||||
|
||||
req = {
|
||||
path: '/',
|
||||
@ -81,18 +76,13 @@ describe('Unit - services/routing/controllers/channel', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.channel(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.channel(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('pass page param', function (done) {
|
||||
@ -108,18 +98,13 @@ describe('Unit - services/routing/controllers/channel', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.channel(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.channel(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('update hbs engine: router defines limit', function (done) {
|
||||
@ -136,19 +121,14 @@ describe('Unit - services/routing/controllers/channel', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.channel(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
themeService.getActive().updateTemplateOptions.withArgs({data: {config: {posts_per_page: 3}}}).calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.channel(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('page param too big', function (done) {
|
||||
@ -170,7 +150,6 @@ describe('Unit - services/routing/controllers/channel', function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.false();
|
||||
renderStub.calledOnce.should.be.false();
|
||||
secureStub.calledOnce.should.be.false();
|
||||
done();
|
||||
@ -190,18 +169,13 @@ describe('Unit - services/routing/controllers/channel', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.channel(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.true();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.channel(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('invalid posts per page', function (done) {
|
||||
@ -217,18 +191,13 @@ describe('Unit - services/routing/controllers/channel', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.channel(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.channel(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('ensure secure helper get\'s called for data object', function (done) {
|
||||
@ -245,17 +214,12 @@ describe('Unit - services/routing/controllers/channel', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.channel(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledTwice.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.channel(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
@ -3,7 +3,6 @@ const should = require('should'),
|
||||
testUtils = require('../../../../utils'),
|
||||
common = require('../../../../../server/lib/common'),
|
||||
security = require('../../../../../server/lib/security'),
|
||||
filters = require('../../../../../server/filters'),
|
||||
themeService = require('../../../../../server/services/themes'),
|
||||
urlService = require('../../../../../server/services/url'),
|
||||
controllers = require('../../../../../server/services/routing/controllers'),
|
||||
@ -48,11 +47,7 @@ describe('Unit - services/routing/controllers/collection', function () {
|
||||
}
|
||||
});
|
||||
|
||||
sinon.stub(helpers, 'renderEntries').get(function () {
|
||||
return renderStub;
|
||||
});
|
||||
|
||||
sinon.stub(filters, 'doFilter');
|
||||
sinon.stub(helpers, 'renderEntries').returns(renderStub);
|
||||
|
||||
sinon.stub(urlService, 'owns');
|
||||
urlService.owns.withArgs('identifier', posts[0].id).returns(true);
|
||||
@ -87,19 +82,14 @@ describe('Unit - services/routing/controllers/collection', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.collection(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledOnce.should.be.true();
|
||||
urlService.owns.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.collection(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('pass page param', function (done) {
|
||||
@ -115,19 +105,14 @@ describe('Unit - services/routing/controllers/collection', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.collection(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledOnce.should.be.true();
|
||||
urlService.owns.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.collection(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('update hbs engine: router defines limit', function (done) {
|
||||
@ -144,20 +129,15 @@ describe('Unit - services/routing/controllers/collection', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.collection(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
themeService.getActive().updateTemplateOptions.withArgs({data: {config: {posts_per_page: 3}}}).calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledOnce.should.be.true();
|
||||
urlService.owns.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.collection(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('page param too big', function (done) {
|
||||
@ -179,7 +159,6 @@ describe('Unit - services/routing/controllers/collection', function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.false();
|
||||
renderStub.calledOnce.should.be.false();
|
||||
secureStub.calledOnce.should.be.false();
|
||||
urlService.owns.calledOnce.should.be.false();
|
||||
@ -200,19 +179,14 @@ describe('Unit - services/routing/controllers/collection', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.collection(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.true();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledOnce.should.be.true();
|
||||
urlService.owns.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.collection(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('invalid posts per page', function (done) {
|
||||
@ -228,19 +202,14 @@ describe('Unit - services/routing/controllers/collection', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.collection(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledOnce.should.be.true();
|
||||
urlService.owns.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.collection(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('ensure secure helper get\'s called for data object', function (done) {
|
||||
@ -257,19 +226,14 @@ describe('Unit - services/routing/controllers/collection', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', posts, res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.collection(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledTwice.should.be.true();
|
||||
urlService.owns.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.collection(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('should verify if post belongs to collection', function (done) {
|
||||
@ -301,18 +265,13 @@ describe('Unit - services/routing/controllers/collection', function () {
|
||||
}
|
||||
});
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', [posts[1]], res.locals).resolves();
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.collection(req, res, failTest(done)).then(function () {
|
||||
themeService.getActive.calledOnce.should.be.true();
|
||||
security.string.safe.calledOnce.should.be.false();
|
||||
fetchDataStub.calledOnce.should.be.true();
|
||||
filters.doFilter.calledOnce.should.be.true();
|
||||
secureStub.calledTwice.should.be.true();
|
||||
urlService.owns.callCount.should.eql(4);
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.collection(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
const should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
testUtils = require('../../../../utils'),
|
||||
filters = require('../../../../../server/filters'),
|
||||
urlService = require('../../../../../server/services/url'),
|
||||
controllers = require('../../../../../server/services/routing/controllers'),
|
||||
helpers = require('../../../../../server/services/routing/helpers'),
|
||||
@ -32,8 +31,6 @@ describe('Unit - services/routing/controllers/entry', function () {
|
||||
return renderStub;
|
||||
});
|
||||
|
||||
sinon.stub(filters, 'doFilter');
|
||||
|
||||
sinon.stub(urlService.utils, 'redirectToAdmin');
|
||||
sinon.stub(urlService.utils, 'redirect301');
|
||||
sinon.stub(urlService, 'getResourceById');
|
||||
@ -75,8 +72,6 @@ describe('Unit - services/routing/controllers/entry', function () {
|
||||
|
||||
res.routerOptions.resourceType = 'posts';
|
||||
|
||||
filters.doFilter.withArgs('prePostsRender', post, res.locals).resolves();
|
||||
|
||||
urlService.getResourceById.withArgs(post.id).returns({
|
||||
config: {
|
||||
type: 'posts'
|
||||
@ -88,12 +83,10 @@ describe('Unit - services/routing/controllers/entry', function () {
|
||||
entry: post
|
||||
});
|
||||
|
||||
renderStub.callsFake(function () {
|
||||
controllers.entry(req, res, function () {
|
||||
secureStub.calledOnce.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.entry(req, res);
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
describe('[edge cases] resource found', function () {
|
||||
|
@ -4,7 +4,6 @@ const should = require('should'),
|
||||
testUtils = require('../../../../utils'),
|
||||
configUtils = require('../../../../utils/configUtils'),
|
||||
api = require('../../../../../server/api'),
|
||||
filters = require('../../../../../server/filters'),
|
||||
controllers = require('../../../../../server/services/routing/controllers'),
|
||||
helpers = require('../../../../../server/services/routing/helpers'),
|
||||
urlService = require('../../../../../server/services/url'),
|
||||
@ -55,7 +54,6 @@ describe('Unit - services/routing/controllers/preview', function () {
|
||||
};
|
||||
|
||||
secureStub = sinon.stub();
|
||||
renderStub = sinon.stub();
|
||||
|
||||
sinon.stub(urlService.utils, 'redirectToAdmin');
|
||||
sinon.stub(urlService.utils, 'redirect301');
|
||||
@ -65,12 +63,13 @@ describe('Unit - services/routing/controllers/preview', function () {
|
||||
return secureStub;
|
||||
});
|
||||
|
||||
renderStub = sinon.stub();
|
||||
sinon.stub(helpers, 'renderEntry').get(function () {
|
||||
return renderStub;
|
||||
return function () {
|
||||
return renderStub;
|
||||
};
|
||||
});
|
||||
|
||||
sinon.stub(filters, 'doFilter');
|
||||
|
||||
sinon.stub(api.posts, 'read').withArgs({
|
||||
uuid: req.params.uuid,
|
||||
status: 'all',
|
||||
@ -81,15 +80,11 @@ describe('Unit - services/routing/controllers/preview', function () {
|
||||
});
|
||||
|
||||
it('should render post', function (done) {
|
||||
filters.doFilter.withArgs('prePostsRender', post, res.locals).resolves();
|
||||
|
||||
helpers.renderEntry.callsFake(function () {
|
||||
renderStub.called.should.be.true();
|
||||
controllers.preview(req, res, failTest(done)).then(function () {
|
||||
secureStub.called.should.be.true();
|
||||
renderStub.called.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.preview(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('should call next if post is not found', function (done) {
|
||||
@ -174,7 +169,6 @@ describe('Unit - services/routing/controllers/preview', function () {
|
||||
};
|
||||
|
||||
secureStub = sinon.stub();
|
||||
renderStub = sinon.stub();
|
||||
|
||||
sinon.stub(urlService.utils, 'redirectToAdmin');
|
||||
sinon.stub(urlService.utils, 'redirect301');
|
||||
@ -184,12 +178,13 @@ describe('Unit - services/routing/controllers/preview', function () {
|
||||
return secureStub;
|
||||
});
|
||||
|
||||
renderStub = sinon.stub();
|
||||
sinon.stub(helpers, 'renderEntry').get(function () {
|
||||
return renderStub;
|
||||
return function () {
|
||||
return renderStub;
|
||||
};
|
||||
});
|
||||
|
||||
sinon.stub(filters, 'doFilter');
|
||||
|
||||
previewStub = sinon.stub();
|
||||
previewStub.withArgs({
|
||||
uuid: req.params.uuid,
|
||||
@ -205,15 +200,11 @@ describe('Unit - services/routing/controllers/preview', function () {
|
||||
});
|
||||
|
||||
it('should render post', function (done) {
|
||||
filters.doFilter.withArgs('prePostsRender', post, res.locals).resolves();
|
||||
|
||||
helpers.renderEntry.callsFake(function () {
|
||||
controllers.preview(req, res, failTest(done)).then(function () {
|
||||
renderStub.called.should.be.true();
|
||||
secureStub.called.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
controllers.preview(req, res, failTest(done));
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user