Permalink
Browse files

[reactivemongo] Count response

  • Loading branch information...
cchantep
cchantep committed Sep 24, 2014
1 parent 9c5d580 commit cb826da6c11d9eac28a9e7a392423fc28aae5a2b
View
@@ -1,6 +1,6 @@
#! /bin/sh
-LIMIT="9c261f107338c4a9d4364d89540f8965cb46c71f"
+LIMIT="9c5d5806bf90bdf8760da0a1c93222b685ce716a"
echo "## $1\n"
View
@@ -306,6 +306,8 @@ val success3 = QueryResponse(Seq(
val success4 = QueryResponse.successful(
BSONDocument("name" -> "singleResult"), BSONDocument("price" -> 1.2D))
+
+val countResponse = QueryResponse.count(4)
```
When a handler supports some query cases, but not other, it can return an undefined response, to let the chance other handlers would manage it.
@@ -1,7 +1,5 @@
package acolyte.reactivemongo
-import scala.concurrent.{ ExecutionContext, Future }
-
/**
* Acolyte DSL for ReactiveMongo.
*/
@@ -26,6 +26,13 @@ object QueryResponse {
/** Factory for successful response. */
def successful(result: BSONDocument*) = apply(result)
+ /**
+ * Prepares a response to a successful count command.
+ *
+ * @param result Count result
+ */
+ def count(result: Int = 0) = apply(BSONDocument("ok" -> 1, "n" -> result))
+
/**
* Empty/undefined response, returned by handler no supporting
* a specific query that may be handled by others.
@@ -84,6 +84,16 @@ object QueryResponseSpec
})
}
}
+
+ "for count command" in {
+ QueryResponse.count(3) aka "prepared" must beLike {
+ case prepared prepared(5) aka "applied" must beSome.which(
+ _ aka "reponse" must beResponse {
+ case ValueDocument(("ok", BSONInteger(1)) ::
+ ("n", BSONInteger(3)) :: Nil) :: Nil ok
+ })
+ }
+ }
}
"be undefined" >> {

0 comments on commit cb826da

Please sign in to comment.