Navigation Menu

Skip to content

Commit

Permalink
Add tests for index field options
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 13, 2012
1 parent d3956d0 commit 1dc1a0a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/database/index-field.js
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
70 changes: 70 additions & 0 deletions test/database-index-field.test.js
Expand Up @@ -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;
Expand Down

0 comments on commit 1dc1a0a

Please sign in to comment.