[Groonga-commit] groonga/gcs [master] Return stored boolean option correctly

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Nov 22 19:04:06 JST 2012


YUKI Hiroshi	2012-11-22 19:04:06 +0900 (Thu, 22 Nov 2012)

  New Revision: 7def2b6c6c16139af1be200571dbbef48e45bc0a
  https://github.com/groonga/gcs/commit/7def2b6c6c16139af1be200571dbbef48e45bc0a

  Log:
    Return stored boolean option correctly

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

  Modified: lib/database/index-field.js (+7 -3)
===================================================================
--- lib/database/index-field.js    2012-11-22 18:51:49 +0900 (ad5033a)
+++ lib/database/index-field.js    2012-11-22 19:04:06 +0900 (8f9f6e4)
@@ -280,6 +280,10 @@ IndexField.prototype = {
       return this._pendingOptions[key];
     return this.domain.getConfiguration(key);
   },
+  getBooleanOption: function(option) {
+    var value = this.getOption(option);
+    return (typeof value == 'boolean') ? value : (value == 'true');
+  },
   setOption: function(option, value) {
     this._pendingOptions = this._pendingOptions || {};
     this._pendingOptions[this.getOptionKey(option)] = value;
@@ -368,7 +372,7 @@ IndexField.prototype = {
     if (this.type == 'uint')
       return false;
 
-    return !!this.getOption('facetEnabled');
+    return this.getBooleanOption('facetEnabled');
   },
   set facetEnabled(value) {
     var booleanValue = !!value;
@@ -391,7 +395,7 @@ IndexField.prototype = {
     if (this.type == 'uint')
       return true;
 
-    return !!this.getOption('resultEnabled');
+    return this.getBooleanOption('resultEnabled');
   },
   set resultEnabled(value) {
     var booleanValue = !!value;
@@ -414,7 +418,7 @@ IndexField.prototype = {
     if (this.type == 'text' || this.type == 'uint')
       return true;
 
-    return !!this.getOption('searchEnabled');
+    return this.getBooleanOption('searchEnabled');
   },
   set searchEnabled(value) {
     var booleanValue = !!value;

  Modified: test/database-index-field.test.js (+23 -0)
===================================================================
--- test/database-index-field.test.js    2012-11-22 18:51:49 +0900 (2b59977)
+++ test/database-index-field.test.js    2012-11-22 19:04:06 +0900 (1f2110d)
@@ -439,6 +439,29 @@ suite('database', function() {
                            another: 'true' });
       });
 
+      test('boolean option', function() {
+        field.setOption('TrueOption', 'true');
+        field.setOption('FalseOption', 'false');
+        field.setOption('NumberOption', '1');
+        field.setOption('TextOption', 'foobar');
+        assert.deepEqual({ rawTrue:       field.getOption('TrueOption'),
+                           booleanTrue:   field.getBooleanOption('TrueOption'),
+                           rawFalse:      field.getOption('FalseOption'),
+                           booleanFalse:  field.getBooleanOption('FalseOption'),
+                           rawNumber:     field.getOption('NumberOption'),
+                           booleanNumber: field.getBooleanOption('NumberOption'),
+                           rawText:       field.getOption('TextOption'),
+                           booleanText:   field.getBooleanOption('TextOption') },
+                         { rawTrue:       'true',
+                           booleanTrue:   true,
+                           rawFalse:      'false',
+                           booleanFalse:  false,
+                           rawNumber:     '1',
+                           booleanNumber: false,
+                           rawText:       'foobar',
+                           booleanText:   false });
+      });
+
       test('hasAnyOption', function() {
         var anotherInstance = new IndexField('field', domain);
 
-------------- next part --------------
HTML����������������������������...
다운로드 



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