Navigation Menu

Skip to content

Commit

Permalink
Throw error for invalid field options
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 13, 2012
1 parent ef6d8f8 commit 9ccf827
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/database/index-field.js
Expand Up @@ -155,6 +155,9 @@ IndexField.prototype = {
return !!(this._facetEnabled = value);
},
set facetEnabled(value) {
if (this.type == 'uint')
throw new Error('facet option cannot be configured for the type ' + this.type);

this._facetEnabled = value;
return value;
},
Expand All @@ -177,6 +180,9 @@ IndexField.prototype = {
return !!(this._resultEnabled = value);
},
set resultEnabled(value) {
if (this.type == 'uint')
throw new Error('returnable option cannot be configured for the type ' + this.type);

this._resultEnabled = value;
return value;
},
Expand All @@ -199,6 +205,9 @@ IndexField.prototype = {
return !!(this._searchEnabled = value);
},
set searchEnabled(value) {
if (this.type == 'text' || this.type == 'uint')
throw new Error('searchable option cannot be configured for the type ' + this.type);

this._searchEnabled = value;
return value;
},
Expand Down
22 changes: 22 additions & 0 deletions test/database-index-field.test.js
Expand Up @@ -242,6 +242,28 @@ suite('database', function() {
assert.equal('Search Facet Result', field.options);
});

test('invalid modification of options for text field', function() {
var field = new IndexField('name', domain).setType('text');
field.createSync();
assert.throw(function() {
field.searchEnabled = false;
}, 'searchable option cannot be configured for the type text');
});

test('invalid modification of options for uint field', function() {
var field = new IndexField('age', domain).setType('uint');
field.createSync();
assert.throw(function() {
field.searchEnabled = false;
}, 'searchable option cannot be configured for the type uint');
assert.throw(function() {
field.facetEnabled = false;
}, 'facet option cannot be configured for the type uint');
assert.throw(function() {
field.resultEnabled = false;
}, 'returnable option cannot be configured for the type uint');
});

test('create literal field with options', function() {
var field = new IndexField('product', domain).setType('literal');
assert.equal('', field.options);
Expand Down

0 comments on commit 9ccf827

Please sign in to comment.