YUKI Hiroshi
null+****@clear*****
Wed Aug 22 16:01:12 JST 2012
YUKI Hiroshi 2012-08-22 16:01:12 +0900 (Wed, 22 Aug 2012) New Revision: c3e5c9a2c31ffe1db9c8c82e6af4b9ef86beeb4f https://github.com/groonga/gcs/commit/c3e5c9a2c31ffe1db9c8c82e6af4b9ef86beeb4f Log: Add gcs-configure-default-search-field command Added files: bin/gcs-configure-default-search-field Modified files: test/gcs-commands.test.js Added: bin/gcs-configure-default-search-field (+33 -0) 100755 =================================================================== --- /dev/null +++ bin/gcs-configure-default-search-field 2012-08-22 16:01:12 +0900 (42b9569) @@ -0,0 +1,33 @@ +#!/usr/bin/env node + +var CLI = require(__dirname + '/../lib/command-line').CommandLineInterface; +var commandLine = new CLI(); +var fs = require('fs'); + +commandLine + .option('-d, --domain-name <domain name>', + 'The name of the domain that you are configuring. Required.', + String) + .option('--name <field name>', + 'The name of the field you want to set as the default search field. ' + + 'It becomes blank if you omit this option', + String) + .parse(); + +commandLine.assertHaveDomainName(); +commandLine.assertDomainExists(); + +var field = commandLine.domain.getIndexField(commandLine.options.name); +if (field) { + console.log('Setting "%s" as the default search field of "%s"...', + field.name, + commandLine.domain.name); +} else if (commandLine.options.name) { + console.log('"%s" is not a field of "%s".'); + return process.exit(1); +} else { + console.log('Resetting the default search field of "%s"...', + commandLine.domain.name); +} +commandLine.domain.defaultSearchField = field; +console.log('Done.'); Modified: test/gcs-commands.test.js (+112 -0) =================================================================== --- test/gcs-commands.test.js 2012-08-22 15:06:34 +0900 (128b68d) +++ test/gcs-commands.test.js 2012-08-22 16:01:12 +0900 (e259ce3) @@ -701,6 +701,118 @@ suite('gcs-configure-text-options', function() { }); }); +suite('gcs-configure-default-search-field', function() { + setup(commonSetup); + teardown(commonTeardown); + + test('set to an existing field', function() { + var domain = new Domain('companies', context).createSync(); + domain.getIndexField('name').setType('text').createSync(); + utils + .run('gcs-configure-default-search-field', + '--domain-name', 'companies', + '--name', 'name', + '--database-path', temporaryDatabase.path) + .next(function(result) { + assert.deepEqual({ code: result.code, + message: result.output.stdout }, + { code: 0, + message: 'Setting "name" as the default search ' + + 'field of "companies"...' + + 'Done.\n' }, + result.output.stderr); + assert.equal(domain.defaultSearchField.name, 'name'); + done(); + }) + .error(function(e) { + done(e); + }); + }); + + test('set to a missing field', function() { + var domain = new Domain('companies', context).createSync(); + domain.getIndexField('name').setType('text').createSync(); + utils + .run('gcs-configure-default-search-field', + '--domain-name', 'companies', + '--name', 'name', + '--database-path', temporaryDatabase.path) + .run('gcs-configure-default-search-field', + '--domain-name', 'companies', + '--name', 'address', + '--database-path', temporaryDatabase.path) + .next(function(result) { + assert.deepEqual({ code: result.code, + message: result.output.stdout }, + { code: 1, + message: '"name" as not a field of "companies".\n' }, + result.output.stderr); + assert.equal(domain.defaultSearchField.name, 'name'); + done(); + }) + .error(function(e) { + done(e); + }); + }); + + test('set to blank', function() { + var domain = new Domain('companies', context).createSync(); + domain.getIndexField('name').setType('text').createSync(); + utils + .run('gcs-configure-default-search-field', + '--domain-name', 'companies', + '--name', 'name', + '--database-path', temporaryDatabase.path) + .run('gcs-configure-default-search-field', + '--domain-name', 'companies', + '--name', '', + '--database-path', temporaryDatabase.path) + .next(function(result) { + assert.deepEqual({ code: result.code, + message: result.output.stdout }, + { code: 0, + message: 'Resetting the default search field of ' + + '"companies"...' + + 'Done.\n' }, + result.output.stderr); + assert.isTrue(domain.defaultSearchField === null, + domain.defaultSearchField); + done(); + }) + .error(function(e) { + done(e); + }); + }); + + test('set to blank (omitted "name" option)', function() { + var domain = new Domain('companies', context).createSync(); + domain.getIndexField('name').setType('text').createSync(); + utils + .run('gcs-configure-default-search-field', + '--domain-name', 'companies', + '--name', 'name', + '--database-path', temporaryDatabase.path) + .run('gcs-configure-default-search-field', + '--domain-name', 'companies', + '--database-path', temporaryDatabase.path) + .next(function(result) { + assert.deepEqual({ code: result.code, + message: result.output.stdout }, + { code: 0, + message: 'Resetting the default search field of ' + + '"companies"...' + + 'Done.\n' }, + result.output.stderr); + assert.isTrue(domain.defaultSearchField === null, + domain.defaultSearchField); + done(); + }) + .error(function(e) { + done(e); + }); + }); +}); + suite('gcs-index-documents', function() { setup(commonSetup); teardown(commonTeardown); -------------- next part -------------- HTML����������������������������...Download