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

Merge pull request #2517 from novaugust/theme_error

Fixed check for a theme's custom error.hbs
This commit is contained in:
Hannah Wolfe 2014-04-06 19:22:29 +01:00
commit 9e358fb922
3 changed files with 52 additions and 8 deletions

View file

@ -9,7 +9,6 @@ var _ = require('lodash'),
// Paths for views // Paths for views
defaultErrorTemplatePath = path.resolve(config().paths.adminViews, 'user-error.hbs'), defaultErrorTemplatePath = path.resolve(config().paths.adminViews, 'user-error.hbs'),
userErrorTemplatePath = path.resolve(config().paths.themePath, 'error.hbs'),
userErrorTemplateExists = false; userErrorTemplateExists = false;
// This is not useful but required for jshint // This is not useful but required for jshint
@ -19,9 +18,8 @@ colors.setTheme({silly: 'rainbow'});
* Basic error handling helpers * Basic error handling helpers
*/ */
errors = { errors = {
updateActiveTheme: function (activeTheme, hasErrorTemplate) { updateActiveTheme: function (activeTheme) {
userErrorTemplatePath = path.resolve(config().paths.themePath, activeTheme, 'error.hbs'); userErrorTemplateExists = config().paths.availableThemes[activeTheme].hasOwnProperty('error.hbs');
userErrorTemplateExists = hasErrorTemplate;
}, },
throwError: function (err) { throwError: function (err) {

View file

@ -118,7 +118,7 @@ function activateTheme(activeTheme) {
expressServer.set('theme view engine', hbs.express3(hbsOptions)); expressServer.set('theme view engine', hbs.express3(hbsOptions));
// Update user error template // Update user error template
errors.updateActiveTheme(activeTheme, config().paths.availableThemes[activeTheme].hasOwnProperty('error')); errors.updateActiveTheme(activeTheme);
} }
// ### ManageAdminAndTheme Middleware // ### ManageAdminAndTheme Middleware

View file

@ -4,10 +4,11 @@ var testUtils = require('../utils'),
when = require('when'), when = require('when'),
sinon = require('sinon'), sinon = require('sinon'),
express = require('express'), express = require('express'),
rewire = require('rewire')
// Stuff we are testing // Stuff we are testing
colors = require('colors'), colors = require('colors'),
errors = require('../../server/errorHandling'), errors = rewire('../../server/errorHandling'),
// storing current environment // storing current environment
currentEnv = process.env.NODE_ENV; currentEnv = process.env.NODE_ENV;
@ -197,10 +198,31 @@ describe('Error handling', function () {
}); });
describe('Rendering', function () { describe('Rendering', function () {
var sandbox; var sandbox,
originalConfig;
before(function () { before(function () {
errors.updateActiveTheme('casper', false); originalConfig = errors.__get__('config');
errors.__set__('config', function () {
return {
'paths': {
'themePath': '/content/themes',
'availableThemes': {
'casper': {
'assets': null,
'default.hbs': '/content/themes/casper/default.hbs',
'index.hbs': '/content/themes/casper/index.hbs',
'page.hbs': '/content/themes/casper/page.hbs',
'tag.hbs': '/content/themes/casper/tag.hbs'
},
'theme-with-error': {
'error.hbs':''
}
}
}
}
});
errors.updateActiveTheme('casper');
}); });
beforeEach(function () { beforeEach(function () {
@ -211,6 +233,9 @@ describe('Error handling', function () {
sandbox.restore(); sandbox.restore();
}); });
after(function () {
errors.__set__('config', originalConfig);
});
it('Renders end-of-middleware 404 errors correctly', function (done) { it('Renders end-of-middleware 404 errors correctly', function (done) {
var req = {method: 'GET'}, var req = {method: 'GET'},
@ -321,5 +346,26 @@ describe('Error handling', function () {
err.code = 500; err.code = 500;
errors.error500(err, req, res, null); errors.error500(err, req, res, null);
}); });
it('Renders custom error template if one exists', function(done){
var code = 404,
error = {message:'Custom view test'},
req = {
session: null
},
res = {
status: function(code) {
return this;
},
render: function(view, model, fn){
view.should.eql('error');
errors.updateActiveTheme('casper');
done();
}
},
next = null;
errors.updateActiveTheme('theme-with-error');
errors.renderErrorPage(code, error, req, res, next);
})
}); });
}); });