[Groonga-commit] groonga/gcs [master] Don't return value for cleared index field

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Dec 5 17:26:00 JST 2012


YUKI Hiroshi	2012-12-05 17:26:00 +0900 (Wed, 05 Dec 2012)

  New Revision: 0449615237552186553689f26037cce715cd8c3e
  https://github.com/groonga/gcs/commit/0449615237552186553689f26037cce715cd8c3e

  Log:
    Don't return value for cleared index field

  Modified files:
    lib/database/index-field.js
    test/database-index-field.test.js

  Modified: lib/database/index-field.js (+14 -10)
===================================================================
--- lib/database/index-field.js    2012-12-05 16:38:51 +0900 (2bb673e)
+++ lib/database/index-field.js    2012-12-05 17:26:00 +0900 (db4af17)
@@ -283,7 +283,7 @@ IndexField.prototype = {
     return value;
   },
   hasOption: function(option) {
-    return this.getOption(option) !== undefined;
+    return typeof this.getOption(option) != undefined;
   },
   getOptionKey: function(option) {
     return 'column_' + this.name + '_option_' + toSnakeCase(option);
@@ -310,27 +310,32 @@ IndexField.prototype = {
     var existingKeys = this.domain.getConfiguration(this.getOptionKey('optionKeys'));
     if (existingKeys) {
       existingKeys.split(',').forEach(function(key) {
-        optionValues[key] = this.domain.getConfiguration(key);
+        if (this._pendingOptions && key in this._pendingOptions)
+          return;
+        var value = this.domain.getConfiguration(key);
+        if (typeof value !== 'undefined')
+          optionValues[key] = value;
       }, this);
     }
     if (this._pendingOptions) {
       Object.keys(this._pendingOptions).forEach(function(key) {
-        optionValues[key] = this._pendingOptions[key];
+        var value = this._pendingOptions[key];
+        if (typeof value !== 'undefined')
+          optionValues[key] = value;
       }, this);
     }
     return optionValues;
   },
   clearAllOptions: function() {
-    var options = this.getAllOptions();
-    Object.keys(options).forEach(function(option) {
+    Object.keys(this.getAllOptions()).forEach(function(option) {
       this.setOption(option, undefined);
     }, this);
+    return this;
   },
   saveOptions: function() {
-    if (!this._pendingOptions) return;
-    var keys = Object.keys(this._pendingOptions);
+    if (!this._pendingOptions) return this;
     var storedKeys = [];
-    keys.forEach(function(key) {
+    Object.keys(this._pendingOptions).forEach(function(key) {
       var value = this._pendingOptions[key];
       if (typeof value == 'undefined') {
         this.domain.deleteConfiguration(key);
@@ -350,8 +355,7 @@ IndexField.prototype = {
     return this;
   },
   hasAnyOption: function() {
-    return !!(this._pendingOptions && Object.keys(this._pendingOptions).length) ||
-           !!this.domain.getConfiguration(this.getOptionKey('optionKeys'));
+    return !!Object.keys(this.getAllOptions().length);
   },
 
 

  Modified: test/database-index-field.test.js (+1 -1)
===================================================================
--- test/database-index-field.test.js    2012-12-05 16:38:51 +0900 (f8b9b47)
+++ test/database-index-field.test.js    2012-12-05 17:26:00 +0900 (08cd7e7)
@@ -524,8 +524,8 @@ suite('database', function() {
 
         field.setOption('Option1', 'false');
         field.setOption('Option2', '1');
-        field.clearAllOptions();
         field.saveOptions();
+        field.clearAllOptions();
         assert.deepEqual(field.getAllOptions(), {});
       });
     });
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index