Ghost/core/test/unit/config_spec.js

184 lines
6.1 KiB
JavaScript
Raw Normal View History

var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
moment = require('moment'),
path = require('path'),
fs = require('fs'),
2014-02-05 12:40:30 +04:00
_ = require('lodash'),
testUtils = require('../utils'),
i18n = require('../../server/i18n'),
utils = require('../../server/utils'),
/*jshint unused:false*/
db = require('../../server/data/db/connection'),
// Thing we are testing
configUtils = require('../utils/configUtils'),
config = configUtils.config,
// storing current environment
currentEnv = process.env.NODE_ENV;
i18n.init();
2014-06-05 01:26:03 +04:00
describe('Config', function () {
before(function () {
configUtils.restore();
});
afterEach(function () {
configUtils.restore();
});
describe('Theme', function () {
beforeEach(function () {
configUtils.set({
url: 'http://my-ghost-blog.com',
theme: {
title: 'casper',
description: 'casper',
logo: 'casper',
cover: 'casper',
timezone: 'Etc/UTC'
}
});
});
it('should have exactly the right keys', function () {
var themeConfig = config.get('theme');
// This will fail if there are any extra keys
themeConfig.should.have.keys('title', 'description', 'logo', 'cover', 'timezone');
});
it('should have the correct values for each key', function () {
var themeConfig = config.get('theme');
// Check values are as we expect
themeConfig.should.have.property('title', 'casper');
themeConfig.should.have.property('description', 'casper');
themeConfig.should.have.property('logo', 'casper');
themeConfig.should.have.property('cover', 'casper');
themeConfig.should.have.property('timezone', 'Etc/UTC');
});
});
describe('Timezone default', function () {
it('should use timezone from settings when set', function () {
var themeConfig = config.get('theme');
// Check values are as we expect
themeConfig.should.have.property('timezone', 'Etc/UTC');
configUtils.set({
theme: {
timezone: 'Africa/Cairo'
}
});
config.get('theme').should.have.property('timezone', 'Africa/Cairo');
});
it('should set theme object with timezone by default', function () {
var themeConfig = configUtils.defaultConfig;
// Check values are as we expect
themeConfig.should.have.property('theme');
themeConfig.theme.should.have.property('timezone', 'Etc/UTC');
});
});
Improve bootstrap flow of a Ghost application addresses #1789, #1364 - Moves ./core/server/loader -> ./core/bootstrap. The bootstrap file is only accessed once during startup, and it’s sole job is to ensure a config.js file exists (creating one if it doesn’t) and then validates the contents of the config file. Since this is directly related to the initializing the application is is appropriate to have it in the ./core folder, named bootstrap as that is what it does. This also improves the dependency graph, as now the bootstrap file require’s the ./core/server/config module and is responsible for passing in the validated config file. Whereas before we had ./core/server/config require’ing ./core/server/loader and running its init code and then passing that value back to itself, the flow is now more straight forward of ./core/bootstrap handling initialization and then instatiation of config module - Merges ./core/server/config/paths into ./core/server/config This flow was always confusing me to that some config options were on the config object, and some were on the paths object. This change now incorporates all of the variables previously defined in config/paths directly into the config module, and in extension, the config.js file. This means that you now have the option of deciding at startup where the content directory for ghost should reside. - broke out loader tests in config_spec to bootstrap_spec - updated all relevant files to now use config().paths - moved urlFor and urlForPost function into ./server/config/url.js
2014-01-05 10:40:53 +04:00
describe('Index', function () {
it('should have exactly the right keys', function () {
var pathConfig = config.get('paths');
// This will fail if there are any extra keys
pathConfig.should.have.keys(
'appRoot',
'internalStoragePath',
'internalSchedulingPath',
'contentPath',
'corePath',
'internalAppPath',
'imagesRelPath',
'adminViews',
'helperTemplates',
'clientAssets'
);
});
it('should have the correct values for each key', function () {
var pathConfig = config.get('paths'),
appRoot = path.resolve(__dirname, '../../../');
pathConfig.should.have.property('appRoot', appRoot);
});
it('should allow specific properties to be user defined', function () {
var contentPath = path.join(config.get('paths').appRoot, 'otherContent', '/');
Improve bootstrap flow of a Ghost application addresses #1789, #1364 - Moves ./core/server/loader -> ./core/bootstrap. The bootstrap file is only accessed once during startup, and it’s sole job is to ensure a config.js file exists (creating one if it doesn’t) and then validates the contents of the config file. Since this is directly related to the initializing the application is is appropriate to have it in the ./core folder, named bootstrap as that is what it does. This also improves the dependency graph, as now the bootstrap file require’s the ./core/server/config module and is responsible for passing in the validated config file. Whereas before we had ./core/server/config require’ing ./core/server/loader and running its init code and then passing that value back to itself, the flow is now more straight forward of ./core/bootstrap handling initialization and then instatiation of config module - Merges ./core/server/config/paths into ./core/server/config This flow was always confusing me to that some config options were on the config object, and some were on the paths object. This change now incorporates all of the variables previously defined in config/paths directly into the config module, and in extension, the config.js file. This means that you now have the option of deciding at startup where the content directory for ghost should reside. - broke out loader tests in config_spec to bootstrap_spec - updated all relevant files to now use config().paths - moved urlFor and urlForPost function into ./server/config/url.js
2014-01-05 10:40:53 +04:00
configUtils.set('paths:contentPath', contentPath);
config.get('paths').should.have.property('contentPath', contentPath);
config.getContentPath('images').should.eql(contentPath + 'images/');
});
});
describe('Storage', function () {
it('should default to local-file-store', function () {
config.get('paths').should.have.property('internalStoragePath', path.join(config.get('paths').corePath, '/server/storage/'));
config.get('storage').should.have.property('active', {
images: 'local-file-store',
themes: 'local-file-store'
});
});
it('no effect: setting a custom active storage as string', function () {
var storagePath = path.join(config.get('paths').contentPath, 'storage', 's3');
configUtils.set({
storage: {
active: 's3',
s3: {}
}
});
config.get('storage').should.have.property('active', 's3');
config.get('storage').should.have.property('s3', {});
});
it('able to set storage for themes (but not officially supported!)', function () {
configUtils.set({
storage: {
active: {
images: 'local-file-store',
themes: 's3'
}
}
});
config.get('storage').should.have.property('active', {
images: 'local-file-store',
themes: 's3'
});
});
it('should allow setting a custom active storage as object', function () {
var storagePath = path.join(config.get('paths').contentPath, 'storage', 's3');
configUtils.set({
storage: {
active: {
images: 's2',
themes: 'local-file-store'
}
}
});
config.get('storage').should.have.property('active', {
images: 's2',
themes: 'local-file-store'
});
});
});
});