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

Merge pull request #5899 from ErisDS/theme-lookup

Remove unnecessary API lookup for activeTheme
This commit is contained in:
Sebastian Gierlinger 2015-09-29 23:27:57 +02:00
commit f7015600b8
2 changed files with 11 additions and 16 deletions

View file

@ -1,7 +1,6 @@
var _ = require('lodash'), var _ = require('lodash'),
express = require('express'), express = require('express'),
path = require('path'), path = require('path'),
api = require('../api'),
config = require('../config'), config = require('../config'),
utils = require('../utils'); utils = require('../utils');
@ -12,11 +11,10 @@ function isBlackListedFileType(file) {
} }
function forwardToExpressStatic(req, res, next) { function forwardToExpressStatic(req, res, next) {
api.settings.read({context: {internal: true}, key: 'activeTheme'}).then(function then(response) { express['static'](
var activeTheme = response.settings[0]; path.join(config.paths.themePath, req.app.get('activeTheme')),
{maxAge: utils.ONE_YEAR_MS}
express['static'](path.join(config.paths.themePath, activeTheme.value), {maxAge: utils.ONE_YEAR_MS})(req, res, next); )(req, res, next);
});
} }
function staticTheme() { function staticTheme() {

View file

@ -2,9 +2,7 @@
/*jshint expr:true*/ /*jshint expr:true*/
var sinon = require('sinon'), var sinon = require('sinon'),
should = require('should'), should = require('should'),
Promise = require('bluebird'),
api = require('../../../server/api'),
express = require('express'), express = require('express'),
staticTheme = require('../../../server/middleware/static-theme'); staticTheme = require('../../../server/middleware/static-theme');
@ -46,23 +44,22 @@ describe('staticTheme', function () {
it('should call express.static if valid file type', function (done) { it('should call express.static if valid file type', function (done) {
var req = { var req = {
url: 'myvalidfile.css' url: 'myvalidfile.css',
app: {
get: function () { return 'casper'; }
}
}, },
settingsStub, activeThemeStub,
sandbox = sinon.sandbox.create(), sandbox = sinon.sandbox.create(),
expressStatic = sinon.spy(express, 'static'); expressStatic = sinon.spy(express, 'static');
settingsStub = sandbox.stub(api.settings, 'read').withArgs(sinon.match.has('key', 'activeTheme')).returns(Promise.resolve({ activeThemeStub = sandbox.spy(req.app, 'get');
settings: [{
key: 'activeKey',
value: 'casper'
}]
}));
staticTheme(null)(req, null, function (reqArg, res, next2) { staticTheme(null)(req, null, function (reqArg, res, next2) {
/*jshint unused:false */ /*jshint unused:false */
sandbox.restore(); sandbox.restore();
next.called.should.be.false; next.called.should.be.false;
activeThemeStub.called.should.be.true;
expressStatic.called.should.be.true; expressStatic.called.should.be.true;
expressStatic.args[0][1].maxAge.should.exist; expressStatic.args[0][1].maxAge.should.exist;
done(); done();