Skip to content

Commit

Permalink
Merge pull request #11 from DjebbZ/master
Browse files Browse the repository at this point in the history
Boolean value comparison
  • Loading branch information
balupton committed May 15, 2012
2 parents 8116872 + 4ac1d09 commit 093fab9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/query-engine.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,11 @@ class Query
if exists and selector.test(value)
match = true

# Boolean
else if _.isBoolean(selector)
if exists and value
match = true

# Conditional Operators
else if _.isObject(selector)
# The $beginsWith operator checks if the value begins with a particular value or values if an array was passed
Expand Down
11 changes: 10 additions & 1 deletion test/queries.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ store =
position: 1
category: 1
date: today
good: true
'jquery':
id: 'jquery'
title: 'jQuery'
Expand All @@ -42,6 +43,7 @@ store =
position: 2
category: 1
date: yesterday
good: false
'history':
id: 'history'
title: 'History.js'
Expand All @@ -60,6 +62,7 @@ store =
position: 1
category: 1
date: today
good: true
'jquery': new Backbone.Model
id: 'jquery'
title: 'jQuery'
Expand All @@ -68,6 +71,7 @@ store =
position: 2
category: 1
date: yesterday
good: false
'history': new Backbone.Model
id: 'history'
title: 'History.js'
Expand Down Expand Up @@ -119,11 +123,16 @@ generateTestSuite = (name,docs) ->
expected = queryEngine.createCollection 'index': docs.get('index')
assert.deepEqual actual.toJSON(), expected.toJSON()

it 'boolean', ->
actual = docs.findAll good: true
expected = queryEngine.createCollection 'index': docs.get('index')
assert.deepEqual actual.toJSON(), expected.toJSON()

it '$and', ->
actual = docs.findAll $all: [{id: 'index'}, {position: 2}]
expected = queryEngine.createCollection()
assert.deepEqual actual.toJSON(), expected.toJSON()

it '$or', ->
actual = docs.findAll $or: [{id: 'index'}, {position: 2}]
expected = queryEngine.createCollection 'index': docs.get('index'), 'jquery': docs.get('jquery')
Expand Down

0 comments on commit 093fab9

Please sign in to comment.