[Groonga-commit] groonga/gcs [master] Add tests for index field options

Back to archive index

SHIMODA Hiroshi null+****@clear*****
Mon Aug 13 17:21:36 JST 2012


SHIMODA Hiroshi	2012-08-13 17:21:36 +0900 (Mon, 13 Aug 2012)

  New Revision: 1dc1a0addab832cb11bb1b410327e5ac80da0d88
  https://github.com/groonga/gcs/commit/1dc1a0addab832cb11bb1b410327e5ac80da0d88

  Log:
    Add tests for index field options

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

  Modified: lib/database/index-field.js (+5 -3)
===================================================================
--- lib/database/index-field.js    2012-08-13 17:09:33 +0900 (a8d1977)
+++ lib/database/index-field.js    2012-08-13 17:21:36 +0900 (51846a3)
@@ -148,7 +148,7 @@ IndexField.prototype = {
     if (this.type == 'uint')
       return false;
 
-    if (this._facetEnabled !== undefined)
+    if (!this.column || this._facetEnabled !== undefined)
       return !!this._facetEnabled;
 
     var value = this.domain.getConfiguration(this.facetEnabledConfigurationKey);
@@ -170,7 +170,7 @@ IndexField.prototype = {
     if (this.type == 'uint')
       return true;
 
-    if (this._resultEnabled !== undefined)
+    if (!this.column || this._resultEnabled !== undefined)
       return !!this._resultEnabled;
 
     var value = this.domain.getConfiguration(this.resultEnabledConfigurationKey);
@@ -192,7 +192,7 @@ IndexField.prototype = {
     if (this.type == 'text' || this.type == 'uint')
       return true;
 
-    if (this._searchEnabled !== undefined)
+    if (!this.column || this._searchEnabled !== undefined)
       return !!this._searchEnabled;
 
     var value = this.domain.getConfiguration(this.searchEnabledConfigurationKey);
@@ -261,6 +261,8 @@ IndexField.prototype = {
     this.saveOptionsSync();
   },
   saveOptionsSync: function() {
+    if (!this.exists()) return;
+
     this.facetEnabled;
     if (this._facetEnabled !== undefined)
       this.domain.setConfiguration(this.facetEnabledConfigurationKey,

  Modified: test/database-index-field.test.js (+70 -0)
===================================================================
--- test/database-index-field.test.js    2012-08-13 17:09:33 +0900 (74e060c)
+++ test/database-index-field.test.js    2012-08-13 17:21:36 +0900 (6a9a352)
@@ -200,6 +200,76 @@ suite('database', function() {
       });
     });
 
+    suite('options', function() {
+      var temporaryDatabase;
+      var context;
+      var domain;
+
+      setup(function() {
+        temporaryDatabase = utils.createTemporaryDatabase();
+        context = temporaryDatabase.get();
+        domain = new Domain('companies', context);
+        domain.createSync();
+      });
+
+      teardown(function() {
+        temporaryDatabase.teardown();
+        temporaryDatabase = undefined;
+      });
+
+      test('create text field with options', function() {
+        var field = new IndexField('name', domain).setType('text');
+        assert.equal('Search', field.options);
+
+        field.facetEnabled = true;
+        field.resultEnabled = true;
+        field.createSync();
+
+        field = new IndexField('name', domain); // reset instance from database
+        assert.equal('Search Facet Result', field.options);
+      });
+
+      test('update text field with options', function() {
+        var field = new IndexField('name', domain).setType('text');
+        field.createSync();
+        assert.equal('Search', field.options);
+
+        field.facetEnabled = true;
+        field.resultEnabled = true;
+        field.saveOptionsSync();
+
+        field = new IndexField('name', domain); // reset instance from database
+        assert.equal('Search Facet Result', field.options);
+      });
+
+      test('create literal field with options', function() {
+        var field = new IndexField('product', domain).setType('literal');
+        assert.equal('', field.options);
+
+        field.searchEnabled = true;
+        field.facetEnabled = true;
+        field.resultEnabled = true;
+        field.createSync();
+
+        field = new IndexField('product', domain); // reset instance from database
+        assert.equal('Search Facet Result', field.options);
+      });
+
+      test('update literal field with options', function() {
+        var field = new IndexField('product', domain).setType('literal');
+        field.createSync();
+        assert.equal('', field.options);
+
+        field.searchEnabled = true;
+        field.facetEnabled = true;
+        field.resultEnabled = true;
+        field.saveOptionsSync();
+
+        field = new IndexField('product', domain); // reset instance from database
+        assert.equal('Search Facet Result', field.options);
+      });
+    });
+
     suite('database modifications', function() {
       var temporaryDatabase;
       var context;
-------------- next part --------------
HTML����������������������������...
다운로드 



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