0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/test/unit/config/index_spec.js
Katharina Irrgang fd0a08ae8c 🎨 make sqlite filename absolute (#7585)
no issue

- add tests for makePathsAbsolute
- add support for windows paths

When Ghost-CLI inits the database of the current GhostVersion (in /current), then it uses knex-migrator to do that.
Knex migrator is reading the .knex-migrator file of the current Ghost version. This returns a relative path to the database location.
The problem: knex-migrator will init the database in the root folder of Ghost-CLI /content/data instead of /current/content . And when you start Ghost (ghost start), it always complains that
that database is not initialised, because it expects the database in /current/content...

* 🎨  move config_spec to config/index_spec
- add one more test case
2016-10-18 09:04:44 +01:00

182 lines
6.1 KiB
JavaScript

var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
moment = require('moment'),
path = require('path'),
fs = require('fs'),
_ = 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;
i18n.init();
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');
});
});
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);
pathConfig.should.have.property('imagesRelPath', 'content/images');
});
it('should allow specific properties to be user defined', function () {
var contentPath = path.join(config.get('paths').appRoot, 'otherContent', '/');
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'
});
});
});
});