Skip to content

Commit

Permalink
Only set nocase opt for string or text values
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Aug 16, 2013
1 parent 2645162 commit f0b8c65
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/query/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Query.prototype = new (function () {
, props
, descr
, datatype
, opts = _createComparisonOpts.apply(this, [keyName]);
, opts;

if (keyName.indexOf('.') > -1) {
keyNameArr = keyName.split('.');
Expand Down Expand Up @@ -184,18 +184,20 @@ Query.prototype = new (function () {
datatype = descr.datatype;
}

opts = _createComparisonOpts.apply(this, [keyName, datatype]);

// TODO: Validate the value for both the particular field
// (e.g., must be a numeric) and the type of comparison
// (e.g., 'IN' must be a collection, etc)
return comparison.create(Query.comparisonTypes[type], modelName,
keyName, val, datatype, opts);
}

, _createComparisonOpts = function (key) {
, _createComparisonOpts = function (key, datatype) {
var opts = this.opts
, nocase = opts.nocase
, ret = {};
if (nocase) {
if (nocase && (datatype == 'string' || datatype == 'text')) {
if (Array.isArray(nocase)) {
if (nocase.some(function (o) {
return o == key;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/zooby.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var model = require('../../lib');

var Zooby = function () {
this.property('foo', 'string', {required: true});
this.property('derf', 'text');
this.property('mar', 'number', {required:true});
this.property('bar', 'number');
this.property('baz', 'int');
Expand Down
12 changes: 12 additions & 0 deletions test/unit/query/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ var tests = {
assert.ok(operands[0] instanceof operation.AndOperation);
}

, 'test condition witn nocase opts flag': function () {
var query = new Query(Zooby, {foo: {like: 'foo'}, bar: null}, {nocase: true});
assert.ok(query.conditions.operands[0].opts.nocase);
assert.ok(!query.conditions.operands[1].opts.nocase);
}

, 'test condition witn nocase opts array': function () {
var query = new Query(Zooby, {foo: {like: 'foo'}, derf: 'blarg'}, {nocase: ['derf']});
assert.ok(!query.conditions.operands[0].opts.nocase);
assert.ok(query.conditions.operands[1].opts.nocase);
}


};

Expand Down

0 comments on commit f0b8c65

Please sign in to comment.