Navigation Menu

Skip to content

Commit

Permalink
Fix minor bugs around gcs-configure-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 13, 2012
1 parent 788afac commit 5b23b6e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 8 additions & 4 deletions bin/gcs-configure-fields
Expand Up @@ -37,6 +37,10 @@ if (!commandLine.options.name) {

var field = commandLine.domain.getIndexField(commandLine.options.name);

var option = commandLine.options.option;
if (typeof option != 'string')
option = null;

if (commandLine.options.delete) {
if (!field.exists()) {
console.log('You must specify an existing field.');
Expand All @@ -51,22 +55,22 @@ if (commandLine.options.delete) {
return process.exit(1);
}
field.type = commandLine.options.type;
} else if (!commandLine.options.option) {
} else if (!option) {
console.log('You must specify the configuring option.');
return process.exit(1);
}

if (commandLine.options.option) {
if (option) {
try {
switch (commandLine.options.option) {
switch (option) {
case 'search': field.searchEnabled = true; break;
case 'nosearch': field.searchEnabled = false; break;
case 'facet': field.facetEnabled = true; break;
case 'nofacet': field.facetEnabled = false; break;
case 'result': field.resultEnabled = true; break;
case 'noresult': field.resultEnabled = false; break;
default:
throw new Error('invalid field option ' + commandLine.options.option);
throw new Error('invalid field option ' + option);
}
} catch(error) {
console.log((error.message || error).toString());
Expand Down
6 changes: 3 additions & 3 deletions lib/database/index-field.js
Expand Up @@ -156,7 +156,7 @@ IndexField.prototype = {
},
set facetEnabled(value) {
if (this.type == 'uint')
throw new Error('facet option cannot be configured for the type ' + this.type);
throw new Error('facet option cannot be configured for the type ' + this.type + '.');

this._facetEnabled = value;
return value;
Expand All @@ -181,7 +181,7 @@ IndexField.prototype = {
},
set resultEnabled(value) {
if (this.type == 'uint')
throw new Error('returnable option cannot be configured for the type ' + this.type);
throw new Error('returnable option cannot be configured for the type ' + this.type + '.');

this._resultEnabled = value;
return value;
Expand All @@ -206,7 +206,7 @@ IndexField.prototype = {
},
set searchEnabled(value) {
if (this.type == 'text' || this.type == 'uint')
throw new Error('searchable option cannot be configured for the type ' + this.type);
throw new Error('searchable option cannot be configured for the type ' + this.type + '.');

this._searchEnabled = value;
return value;
Expand Down
8 changes: 7 additions & 1 deletion test/gcs-commands.test.js
Expand Up @@ -369,7 +369,7 @@ suite('gcs-configure-fields', function() {
assert.deepEqual({ code: result.code,
message: result.output.stdout },
{ code: 1,
message: 'You must specify not-existing field name.\n' },
message: 'You must specify the configuring option.\n' },
result.output.stderr);
done();
})
Expand Down Expand Up @@ -471,6 +471,7 @@ suite('gcs-configure-fields', function() {
domain.getIndexField(name).setType(type).createSync();
utils
.run('gcs-configure-fields',
'--domain-name', 'companies',
'--name', name,
'--option', 'search',
'--database-path', temporaryDatabase.path)
Expand All @@ -481,6 +482,7 @@ suite('gcs-configure-fields', function() {
assertOptionConfigured(result, name, type, results.search);
})
.run('gcs-configure-fields',
'--domain-name', 'companies',
'--name', name,
'--option', 'nosearch',
'--database-path', temporaryDatabase.path)
Expand All @@ -491,6 +493,7 @@ suite('gcs-configure-fields', function() {
assertOptionConfigured(result, name, type, results.nosearch);
})
.run('gcs-configure-fields',
'--domain-name', 'companies',
'--name', name,
'--option', 'result',
'--database-path', temporaryDatabase.path)
Expand All @@ -501,6 +504,7 @@ suite('gcs-configure-fields', function() {
assertOptionConfigured(result, name, type, results.result);
})
.run('gcs-configure-fields',
'--domain-name', 'companies',
'--name', name,
'--option', 'noresult',
'--database-path', temporaryDatabase.path)
Expand All @@ -511,6 +515,7 @@ suite('gcs-configure-fields', function() {
assertOptionConfigured(result, name, type, results.noresult);
})
.run('gcs-configure-fields',
'--domain-name', 'companies',
'--name', name,
'--option', 'facet',
'--database-path', temporaryDatabase.path)
Expand All @@ -521,6 +526,7 @@ suite('gcs-configure-fields', function() {
assertOptionConfigured(result, name, type, results.facet);
})
.run('gcs-configure-fields',
'--domain-name', 'companies',
'--name', name,
'--option', 'nofacet',
'--database-path', temporaryDatabase.path)
Expand Down

0 comments on commit 5b23b6e

Please sign in to comment.