YUKI Hiroshi
null+****@clear*****
Thu Nov 22 17:57:42 JST 2012
YUKI Hiroshi 2012-11-22 17:57:42 +0900 (Thu, 22 Nov 2012) New Revision: 8e8bba56d409e01653a81be453adb27c8e2f45ce https://github.com/groonga/gcs/commit/8e8bba56d409e01653a81be453adb27c8e2f45ce Log: Add tests for full options Modified files: lib/database/index-field.js test/database-index-field.test.js Modified: lib/database/index-field.js (+3 -2) =================================================================== --- lib/database/index-field.js 2012-11-22 17:32:58 +0900 (2a8b514) +++ lib/database/index-field.js 2012-11-22 17:57:42 +0900 (50a7276) @@ -336,11 +336,12 @@ IndexField.prototype = { }); } this.domain.setConfiguration(this.getOptionKey('optionKeys'), keys.join(',')); - this._pendingOptions = {}; + delete this._pendingOptions; return this; }, hasAnyOption: function() { - return !!this.domain.getConfiguration(this.getOptionKey('optionKeys')); + return !!(this._pendingOptions && Object.keys(this._pendingOptions).length) || + !!this.domain.getConfiguration(this.getOptionKey('optionKeys')); }, Modified: test/database-index-field.test.js (+106 -1) =================================================================== --- test/database-index-field.test.js 2012-11-22 17:32:58 +0900 (419cd60) +++ test/database-index-field.test.js 2012-11-22 17:57:42 +0900 (2b59977) @@ -244,7 +244,7 @@ suite('database', function() { }); }); - suite('options', function() { + suite('major options', function() { var temporaryDatabase; var context; var domain; @@ -389,6 +389,111 @@ suite('database', function() { }); }); + suite('full options', function() { + var temporaryDatabase; + var context; + var domain; + var field; + + setup(function() { + temporaryDatabase = utils.createTemporaryDatabase(); + context = temporaryDatabase.get(); + domain = new Domain('companies', context); + domain.saveSync(); + field = domain.getIndexField('field').setType('text'); + }); + + teardown(function() { + temporaryDatabase.teardown(); + temporaryDatabase = undefined; + field = undefined; + }); + + test('initial state', function() { + var actual = { + hasAnyOption: field.hasAnyOption(), + getAllOptions: {}, + getAllRawOptions: {} + }; + var expected = { + hasAnyOption: false, + getAllOptions: {}, + getAllRawOptions: {} + }; + assert.deepEqual(actual, expected); + }); + + test('get and set', function() { + var anotherInstance = new IndexField('field', domain); + + field.setOption('FooBar', 'true'); + assert.deepEqual({ source: field.getOption('FooBar'), + another: anotherInstance.getOption('FooBar') }, + { source: 'true', + another: undefined }); + + field.saveOptions(); + assert.deepEqual({ source: field.getOption('FooBar'), + another: anotherInstance.getOption('FooBar') }, + { source: 'true', + another: 'true' }); + }); + + test('hasAnyOption', function() { + var anotherInstance = new IndexField('field', domain); + + field.setOption('FooBar', 'true'); + assert.deepEqual({ source: field.hasAnyOption(), + another: anotherInstance.hasAnyOption() }, + { source: true, + another: false }); + + field.saveOptions(); + assert.deepEqual({ source: field.hasAnyOption(), + another: anotherInstance.hasAnyOption() }, + { source: true, + another: true }); + }); + + test('setOptions', function() { + field.setOptions({ + Option1: 'true', + Option2: '0' + }); + var actual = { + Option1: field.getOption('Option1'), + Option2: field.getOption('Option2') + }; + var expected = { + Option1: 'true', + Option2: '0' + }; + assert.deepEqual(actual, expected); + + field.saveOptions(); + actual = { + Option1: field.getOption('Option1'), + Option2: field.getOption('Option2') + }; + assert.deepEqual(actual, expected); + }); + + test('getAllOptions', function() { + field.setOption('Option1', 'false'); + field.setOption('Option2', '1'); + var actual = field.getAllOptions(); + var expected = { + Option1: 'false', + Option2: '1' + }; + assert.deepEqual(actual, expected); + + field.saveOptions(); + actual = field.getAllOptions(); + assert.deepEqual(actual, expected); + }); + }); + suite('database modifications', function() { var temporaryDatabase; var context; -------------- next part -------------- HTML����������������������������...Download