Skip to content

Commit 9126a47

Browse files
committed
fix(config): run environment check when not part of ghost setup
closes #265 - add ignoreEnvCheck flag to config command - fix tests - fix prompts to skip mysql prompts if sqlite is defined in config already
1 parent 7f51138 commit 9126a47

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

lib/commands/config/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ class ConfigCommand extends Command {
8787
});
8888
}
8989

90-
if (!argv.db || argv.db !== 'sqlite3') {
90+
const db = argv.db || this.instance.config.get('database.client');
91+
92+
if (!db || db !== 'sqlite3') {
9193
if (!argv.dbhost) {
9294
prompts.push({
9395
type: 'input',
@@ -135,8 +137,11 @@ class ConfigCommand extends Command {
135137
const key = argv.key;
136138
let value = argv.value;
137139

138-
if (key && !value) {
140+
if (key || !argv.ignoreEnvCheck) {
139141
this.instance.checkEnvironment();
142+
}
143+
144+
if (key && !value) {
140145
// getter
141146
value = this.instance.config.get(key, null);
142147

@@ -146,7 +151,6 @@ class ConfigCommand extends Command {
146151

147152
return Promise.resolve();
148153
} else if (key) {
149-
this.instance.checkEnvironment();
150154
// setter
151155
this.instance.config.set(key, value).save();
152156
return Promise.resolve();

lib/commands/setup.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ class SetupCommand extends Command {
119119
});
120120
}
121121

122-
return this.ui.run(() => this.runCommand(ConfigCommand, argv), 'Configuring Ghost').then(
122+
return this.ui.run(
123+
() => this.runCommand(ConfigCommand, Object.assign({ignoreEnvCheck: true}, argv)),
124+
'Configuring Ghost'
125+
).then(
123126
() => this.system.hook('setup', this, argv)
124127
).then(() => {
125128
const taskMap = {};

test/unit/commands/config-spec.js

+33-5
Original file line numberDiff line numberDiff line change
@@ -291,30 +291,52 @@ describe('Unit: Command > Config', function () {
291291
});
292292

293293
it('calls handleAdvancedOptions without prompts if no-prompt is set', function () {
294-
const getInstanceStub = sinon.stub().returns({});
294+
const checkEnvironmentStub = sinon.stub();
295+
const getInstanceStub = sinon.stub().returns({checkEnvironment: checkEnvironmentStub});
295296

296297
const config = new ConfigCommand({}, {getInstance: getInstanceStub});
297298
const getConfigPromptsStub = sinon.stub(config, 'getConfigPrompts').returns([]);
298299
const handleAdvancedOptionsStub = sinon.stub(config, 'handleAdvancedOptions').resolves({result: true});
299300

300301
return config.run({prompt: false}).then((result) => {
301302
expect(result).to.deep.equal({result: true});
303+
expect(checkEnvironmentStub.calledOnce).to.be.true;
302304
expect(getConfigPromptsStub.calledOnce).to.be.true;
303305
expect(getConfigPromptsStub.args[0][0]).to.deep.equal({prompt: false});
304306
expect(handleAdvancedOptionsStub.calledOnce).to.be.true;
305307
expect(handleAdvancedOptionsStub.args[0][0]).to.deep.equal({prompt: false});
306308
});
307309
});
308310

311+
it('does not call checkEnvironment if ignoreEnvCheck is passed', function () {
312+
const checkEnvironmentStub = sinon.stub();
313+
const getInstanceStub = sinon.stub().returns({checkEnvironment: checkEnvironmentStub});
314+
315+
const config = new ConfigCommand({}, {getInstance: getInstanceStub});
316+
const getConfigPromptsStub = sinon.stub(config, 'getConfigPrompts').returns([]);
317+
const handleAdvancedOptionsStub = sinon.stub(config, 'handleAdvancedOptions').resolves({result: true});
318+
319+
return config.run({prompt: false, ignoreEnvCheck: true}).then((result) => {
320+
expect(result).to.deep.equal({result: true});
321+
expect(checkEnvironmentStub.called).to.be.false;
322+
expect(getConfigPromptsStub.calledOnce).to.be.true;
323+
expect(getConfigPromptsStub.args[0][0]).to.deep.equal({prompt: false, ignoreEnvCheck: true});
324+
expect(handleAdvancedOptionsStub.calledOnce).to.be.true;
325+
expect(handleAdvancedOptionsStub.args[0][0]).to.deep.equal({prompt: false, ignoreEnvCheck: true});
326+
});
327+
});
328+
309329
it('calls handleAdvancedOptions without prompts if no prompts are needed', function () {
310-
const getInstanceStub = sinon.stub().returns({});
330+
const checkEnvironmentStub = sinon.stub();
331+
const getInstanceStub = sinon.stub().returns({checkEnvironment: checkEnvironmentStub});
311332

312333
const config = new ConfigCommand({}, {getInstance: getInstanceStub});
313334
const getConfigPromptsStub = sinon.stub(config, 'getConfigPrompts').returns([]);
314335
const handleAdvancedOptionsStub = sinon.stub(config, 'handleAdvancedOptions').resolves({result: true});
315336

316337
return config.run({prompt: true}).then((result) => {
317338
expect(result).to.deep.equal({result: true});
339+
expect(checkEnvironmentStub.calledOnce).to.be.true;
318340
expect(getConfigPromptsStub.calledOnce).to.be.true;
319341
expect(getConfigPromptsStub.args[0][0]).to.deep.equal({prompt: true});
320342
expect(handleAdvancedOptionsStub.calledOnce).to.be.true;
@@ -323,7 +345,8 @@ describe('Unit: Command > Config', function () {
323345
});
324346

325347
it('prompts with defined prompts, passes result to handleAdvancedOptions', function () {
326-
const getInstanceStub = sinon.stub().returns({});
348+
const checkEnvironmentStub = sinon.stub();
349+
const getInstanceStub = sinon.stub().returns({checkEnvironment: checkEnvironmentStub});
327350
const promptStub = sinon.stub().resolves({});
328351

329352
const config = new ConfigCommand({prompt: promptStub}, {getInstance: getInstanceStub});
@@ -332,6 +355,7 @@ describe('Unit: Command > Config', function () {
332355

333356
return config.run({prompt: true}).then((result) => {
334357
expect(result).to.deep.equal({result: true});
358+
expect(checkEnvironmentStub.calledOnce).to.be.true;
335359
expect(getConfigPromptsStub.calledOnce).to.be.true;
336360
expect(getConfigPromptsStub.args[0][0]).to.deep.equal({prompt: true});
337361
expect(promptStub.calledOnce).to.be.true;
@@ -342,7 +366,8 @@ describe('Unit: Command > Config', function () {
342366
});
343367

344368
it('sets db to mysql if dbhost is provided via prompts', function () {
345-
const getInstanceStub = sinon.stub().returns({});
369+
const checkEnvironmentStub = sinon.stub();
370+
const getInstanceStub = sinon.stub().returns({checkEnvironment: checkEnvironmentStub});
346371
const promptStub = sinon.stub().resolves({dbhost: 'localhost'});
347372

348373
const config = new ConfigCommand({prompt: promptStub}, {getInstance: getInstanceStub});
@@ -351,6 +376,7 @@ describe('Unit: Command > Config', function () {
351376

352377
return config.run({prompt: true}).then((result) => {
353378
expect(result).to.deep.equal({result: true});
379+
expect(checkEnvironmentStub.calledOnce).to.be.true;
354380
expect(getConfigPromptsStub.calledOnce).to.be.true;
355381
expect(getConfigPromptsStub.args[0][0]).to.deep.equal({prompt: true, db: 'mysql', dbhost: 'localhost'});
356382
expect(promptStub.calledOnce).to.be.true;
@@ -361,7 +387,8 @@ describe('Unit: Command > Config', function () {
361387
});
362388

363389
it('doesn\'t add null prompt values to argv object', function () {
364-
const getInstanceStub = sinon.stub().returns({});
390+
const checkEnvironmentStub = sinon.stub();
391+
const getInstanceStub = sinon.stub().returns({checkEnvironment: checkEnvironmentStub});
365392
const promptStub = sinon.stub().resolves({dbhost: 'localhost', dbpass: ''});
366393

367394
const config = new ConfigCommand({prompt: promptStub}, {getInstance: getInstanceStub});
@@ -370,6 +397,7 @@ describe('Unit: Command > Config', function () {
370397

371398
return config.run({prompt: true}).then((result) => {
372399
expect(result).to.deep.equal({result: true});
400+
expect(checkEnvironmentStub.calledOnce).to.be.true;
373401
expect(getConfigPromptsStub.calledOnce).to.be.true;
374402
expect(getConfigPromptsStub.args[0][0]).to.deep.equal({prompt: true, db: 'mysql', dbhost: 'localhost'});
375403
expect(promptStub.calledOnce).to.be.true;

0 commit comments

Comments
 (0)