SHIMODA Hiroshi
null+****@clear*****
Mon Aug 13 18:00:25 JST 2012
SHIMODA Hiroshi 2012-08-13 18:00:25 +0900 (Mon, 13 Aug 2012) New Revision: 9ccf8274171fcd1013c8b407649fdc0822c81b50 https://github.com/groonga/gcs/commit/9ccf8274171fcd1013c8b407649fdc0822c81b50 Log: Throw error for invalid field options Modified files: lib/database/index-field.js test/database-index-field.test.js Modified: lib/database/index-field.js (+9 -0) =================================================================== --- lib/database/index-field.js 2012-08-13 17:46:29 +0900 (51846a3) +++ lib/database/index-field.js 2012-08-13 18:00:25 +0900 (e75ccdf) @@ -155,6 +155,9 @@ IndexField.prototype = { return !!(this._facetEnabled = value); }, set facetEnabled(value) { + if (this.type == 'uint') + throw new Error('facet option cannot be configured for the type ' + this.type); + this._facetEnabled = value; return value; }, @@ -177,6 +180,9 @@ IndexField.prototype = { return !!(this._resultEnabled = value); }, set resultEnabled(value) { + if (this.type == 'uint') + throw new Error('returnable option cannot be configured for the type ' + this.type); + this._resultEnabled = value; return value; }, @@ -199,6 +205,9 @@ IndexField.prototype = { return !!(this._searchEnabled = value); }, set searchEnabled(value) { + if (this.type == 'text' || this.type == 'uint') + throw new Error('searchable option cannot be configured for the type ' + this.type); + this._searchEnabled = value; return value; }, Modified: test/database-index-field.test.js (+22 -0) =================================================================== --- test/database-index-field.test.js 2012-08-13 17:46:29 +0900 (6a9a352) +++ test/database-index-field.test.js 2012-08-13 18:00:25 +0900 (5566f2b) @@ -242,6 +242,28 @@ suite('database', function() { assert.equal('Search Facet Result', field.options); }); + test('invalid modification of options for text field', function() { + var field = new IndexField('name', domain).setType('text'); + field.createSync(); + assert.throw(function() { + field.searchEnabled = false; + }, 'searchable option cannot be configured for the type text'); + }); + + test('invalid modification of options for uint field', function() { + var field = new IndexField('age', domain).setType('uint'); + field.createSync(); + assert.throw(function() { + field.searchEnabled = false; + }, 'searchable option cannot be configured for the type uint'); + assert.throw(function() { + field.facetEnabled = false; + }, 'facet option cannot be configured for the type uint'); + assert.throw(function() { + field.resultEnabled = false; + }, 'returnable option cannot be configured for the type uint'); + }); + test('create literal field with options', function() { var field = new IndexField('product', domain).setType('literal'); assert.equal('', field.options); -------------- next part -------------- HTML����������������������������...Download