mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
More robust deprecation check code
Closes #4082 * reformatted code to allow for traversal * deeper config items should be denoted like this: `object.object.object.property`. * added tests for testing the deprecation warnings
This commit is contained in:
parent
438444df3d
commit
b3820fbb31
2 changed files with 95 additions and 9 deletions
|
@ -322,17 +322,31 @@ ConfigManager.prototype.checkDeprecated = function () {
|
|||
var deprecatedItems = ['updateCheck'],
|
||||
self = this;
|
||||
|
||||
_.each(deprecatedItems, function (item) {
|
||||
if (self.hasOwnProperty(item)) {
|
||||
var errorText = 'The configuration property [' + item.toString().bold + '] has been deprecated.',
|
||||
explinationText = 'This will be removed in a future version, please update your config.js file.',
|
||||
helpText = 'Please check http://support.ghost.org/config for the most up-to-date example.';
|
||||
|
||||
errors.logWarn(errorText, explinationText, helpText);
|
||||
}
|
||||
_.each(deprecatedItems, function (property) {
|
||||
self.displayDeprecated(self, property.split('.'), []);
|
||||
});
|
||||
};
|
||||
|
||||
ConfigManager.prototype.displayDeprecated = function (item, properties, address) {
|
||||
var self = this,
|
||||
property = properties.shift(),
|
||||
errorText,
|
||||
explanationText,
|
||||
helpText;
|
||||
|
||||
address.push(property);
|
||||
|
||||
if (item.hasOwnProperty(property)) {
|
||||
if (properties.length) {
|
||||
return self.displayDeprecated(item[property], properties, address);
|
||||
}
|
||||
errorText = 'The configuration property [' + address.join('.').bold + '] has been deprecated.';
|
||||
explanationText = 'This will be removed in a future version, please update your config.js file.';
|
||||
helpText = 'Please check http://support.ghost.org/config for the most up-to-date example.';
|
||||
errors.logWarn(errorText, explanationText, helpText);
|
||||
}
|
||||
};
|
||||
|
||||
if (testingEnvs.indexOf(process.env.NODE_ENV) > -1) {
|
||||
defaultConfig = require('../../../config.example')[process.env.NODE_ENV];
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@ var should = require('should'),
|
|||
|
||||
// Thing we are testing
|
||||
defaultConfig = require('../../../config.example')[process.env.NODE_ENV],
|
||||
config = rewire('../../server/config');
|
||||
config = rewire('../../server/config'),
|
||||
// storing current environment
|
||||
currentEnv = process.env.NODE_ENV;
|
||||
|
||||
// To stop jshint complaining
|
||||
should.equal(true, true);
|
||||
|
@ -677,4 +679,74 @@ describe('Config', function () {
|
|||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Deprecated', function () {
|
||||
var logStub,
|
||||
// Can't use afterEach here, because mocha uses console.log to output the checkboxes
|
||||
// which we've just stubbed, so we need to restore it before the test ends to see ticks.
|
||||
resetEnvironment = function () {
|
||||
logStub.restore();
|
||||
process.env.NODE_ENV = currentEnv;
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
logStub = sinon.stub(console, 'log');
|
||||
process.env.NODE_ENV = 'development';
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
// logStub.restore();
|
||||
config = rewire('../../server/config');
|
||||
});
|
||||
|
||||
it('doesn\'t display warning when deprecated options not set', function () {
|
||||
config.checkDeprecated();
|
||||
logStub.calledOnce.should.be.false;
|
||||
|
||||
// Future tests: This is important here!
|
||||
resetEnvironment();
|
||||
});
|
||||
|
||||
it('displays warning when updateCheck exists and is truthy', function () {
|
||||
config.set({
|
||||
updateCheck: 'foo'
|
||||
});
|
||||
// Run the test code
|
||||
config.checkDeprecated();
|
||||
|
||||
logStub.calledOnce.should.be.true;
|
||||
logStub.calledWith(
|
||||
'\nWarning:'.yellow,
|
||||
('The configuration property [' + 'updateCheck'.bold + '] has been deprecated.').yellow,
|
||||
'\n',
|
||||
'This will be removed in a future version, please update your config.js file.'.white,
|
||||
'\n',
|
||||
'Please check http://support.ghost.org/config for the most up-to-date example.'.green,
|
||||
'\n').should.be.true;
|
||||
|
||||
// Future tests: This is important here!
|
||||
resetEnvironment();
|
||||
});
|
||||
|
||||
it('displays warning when updateCheck exists and is falsy', function () {
|
||||
config.set({
|
||||
updateCheck: undefined
|
||||
});
|
||||
// Run the test code
|
||||
config.checkDeprecated();
|
||||
|
||||
logStub.calledOnce.should.be.true;
|
||||
logStub.calledWith(
|
||||
'\nWarning:'.yellow,
|
||||
('The configuration property [' + 'updateCheck'.bold + '] has been deprecated.').yellow,
|
||||
'\n',
|
||||
'This will be removed in a future version, please update your config.js file.'.white,
|
||||
'\n',
|
||||
'Please check http://support.ghost.org/config for the most up-to-date example.'.green,
|
||||
'\n').should.be.true;
|
||||
|
||||
// Future tests: This is important here!
|
||||
resetEnvironment();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue