Skip to content

Commit

Permalink
Added a trait exemplar for Typed Criteria DSL.
Browse files Browse the repository at this point in the history
Since filters (criteria) are concerned with constraining a result
set, they do not necessarily have to exist as a type which will
be instantiated.  This change serves to verify that fact.
  • Loading branch information
osxhacker authored and fehmicansaglam committed Jul 7, 2014
1 parent 4dfc7a4 commit 2b217aa
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion samples/src/test/scala/dsl/criteria/TypedCriteriaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ import org.scalatest.junit.JUnitRunner
import reactivemongo.bson._
import reactivemongo.extensions.dsl.criteria._

trait Company {
val name: String;
val employees: Int;
}

case class Person(val firstName: String, val lastName: String, age: Int)

/**
* The '''TypedCriteriaSpec''' type verifies the
* The '''TypedCriteriaSpec''' type verifies the expected behaviour of the
* [[reactivemongo.extensions.dsl.criteria.Typed]] Criteria DSL.
*
* @author svickers
Expand Down Expand Up @@ -64,5 +69,28 @@ class TypedCriteriaSpec
)
);
}

it should "support trait-based expressions" in
{
val query = criteria[Company].employees === 42 ||
criteria[Company].employees < 10;

BSONDocument.pretty(query) shouldBe (
BSONDocument.pretty(
BSONDocument(
"$or" ->
BSONArray(
BSONDocument(
"employees" -> BSONInteger(42)
),
BSONDocument(
"employees" ->
BSONDocument("$lt" -> 10)
)
)
)
)
);
}
}

0 comments on commit 2b217aa

Please sign in to comment.