2013-12-26 07:15:10 -05:00
|
|
|
/*globals describe, it, beforeEach, afterEach */
|
|
|
|
|
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
when = require('when'),
|
2013-12-28 11:01:08 -05:00
|
|
|
path = require('path'),
|
2013-12-26 07:15:10 -05:00
|
|
|
|
|
|
|
config = require('../../server/config');
|
|
|
|
|
|
|
|
describe('Config', function () {
|
|
|
|
|
|
|
|
describe('Theme', function () {
|
|
|
|
|
|
|
|
var sandbox,
|
2013-12-28 11:01:08 -05:00
|
|
|
settings,
|
2013-12-26 07:15:10 -05:00
|
|
|
settingsStub;
|
|
|
|
|
|
|
|
beforeEach(function (done) {
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
2013-12-28 11:01:08 -05:00
|
|
|
settings = {'read': function read() {}};
|
2013-12-26 07:15:10 -05:00
|
|
|
|
|
|
|
settingsStub = sandbox.stub(settings, 'read', function () {
|
|
|
|
return when({value: 'casper'});
|
|
|
|
});
|
|
|
|
|
|
|
|
config.theme.update(settings, 'http://my-ghost-blog.com')
|
|
|
|
.then(done)
|
2013-12-28 11:01:08 -05:00
|
|
|
.then(null, done);
|
2013-12-26 07:15:10 -05:00
|
|
|
});
|
|
|
|
|
2013-12-28 11:01:08 -05:00
|
|
|
afterEach(function (done) {
|
|
|
|
config.theme.update(settings, config().url)
|
|
|
|
.then(done)
|
|
|
|
.then(null, done);
|
|
|
|
|
2013-12-26 07:15:10 -05:00
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
2013-12-28 11:01:08 -05:00
|
|
|
it('should have exactly the right keys', function () {
|
2013-12-26 07:15:10 -05:00
|
|
|
var themeConfig = config.theme();
|
|
|
|
|
|
|
|
// This will fail if there are any extra keys
|
|
|
|
themeConfig.should.have.keys('url', 'title', 'description', 'logo', 'cover');
|
2013-12-28 11:01:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should have the correct values for each key', function () {
|
|
|
|
var themeConfig = config.theme();
|
2013-12-26 07:15:10 -05:00
|
|
|
|
|
|
|
// Check values are as we expect
|
|
|
|
themeConfig.should.have.property('url', 'http://my-ghost-blog.com');
|
|
|
|
themeConfig.should.have.property('title', 'casper');
|
|
|
|
themeConfig.should.have.property('description', 'casper');
|
|
|
|
themeConfig.should.have.property('logo', 'casper');
|
|
|
|
themeConfig.should.have.property('cover', 'casper');
|
|
|
|
|
|
|
|
// Check settings.read gets called exactly 4 times
|
|
|
|
settingsStub.callCount.should.equal(4);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-28 11:01:08 -05:00
|
|
|
describe('Paths', function () {
|
|
|
|
var sandbox;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
config.paths.update(config().url)
|
|
|
|
.then(done)
|
|
|
|
.then(null, done);
|
|
|
|
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have exactly the right keys', function () {
|
|
|
|
var pathConfig = config.paths();
|
|
|
|
|
|
|
|
// This will fail if there are any extra keys
|
|
|
|
pathConfig.should.have.keys(
|
|
|
|
'appRoot',
|
|
|
|
'subdir',
|
|
|
|
'config',
|
|
|
|
'configExample',
|
|
|
|
'contentPath',
|
|
|
|
'corePath',
|
|
|
|
'themePath',
|
|
|
|
'pluginPath',
|
|
|
|
'imagesPath',
|
|
|
|
'imagesRelPath',
|
|
|
|
'adminViews',
|
|
|
|
'helperTemplates',
|
2013-12-29 18:52:55 -05:00
|
|
|
'exportPath',
|
2013-12-28 11:01:08 -05:00
|
|
|
'lang',
|
2013-12-29 18:52:55 -05:00
|
|
|
'debugPath',
|
2013-12-28 11:01:08 -05:00
|
|
|
'availableThemes',
|
|
|
|
'availablePlugins'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have the correct values for each key', function () {
|
|
|
|
var pathConfig = config.paths(),
|
|
|
|
appRoot = path.resolve(__dirname, '../../../');
|
|
|
|
|
|
|
|
pathConfig.should.have.property('appRoot', appRoot);
|
|
|
|
pathConfig.should.have.property('subdir', '');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not return a slash for subdir', function (done) {
|
|
|
|
config.paths.update('http://my-ghost-blog.com').then(function () {
|
|
|
|
config.paths().should.have.property('subdir', '');
|
|
|
|
|
|
|
|
return config.paths.update('http://my-ghost-blog.com/');
|
|
|
|
}).then(function () {
|
|
|
|
config.paths().should.have.property('subdir', '');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).otherwise(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle subdirectories properly', function (done) {
|
|
|
|
config.paths.update('http://my-ghost-blog.com/blog').then(function () {
|
|
|
|
config.paths().should.have.property('subdir', '/blog');
|
|
|
|
|
|
|
|
return config.paths.update('http://my-ghost-blog.com/blog/');
|
|
|
|
}).then(function () {
|
|
|
|
config.paths().should.have.property('subdir', '/blog');
|
|
|
|
|
|
|
|
return config.paths.update('http://my-ghost-blog.com/my/blog');
|
|
|
|
}).then(function () {
|
|
|
|
config.paths().should.have.property('subdir', '/my/blog');
|
|
|
|
|
|
|
|
return config.paths.update('http://my-ghost-blog.com/my/blog/');
|
|
|
|
}).then(function () {
|
|
|
|
config.paths().should.have.property('subdir', '/my/blog');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).otherwise(done);
|
|
|
|
});
|
|
|
|
});
|
2013-12-26 07:15:10 -05:00
|
|
|
});
|