Permalink
Browse files

[reactivemongo] BSON array extractor

  • Loading branch information...
cchantep
cchantep committed Sep 25, 2014
1 parent bb96d08 commit b663965aa94b91a6e573ac760a1ba3e20ea6fb0b
@@ -2,7 +2,7 @@ package acolyte.reactivemongo
import org.jboss.netty.buffer.ChannelBuffer
-import reactivemongo.bson.{ BSONDocument, BSONString, BSONValue }
+import reactivemongo.bson.{ BSONArray, BSONDocument, BSONString, BSONValue }
import reactivemongo.bson.buffer.{
ArrayBSONBuffer,
ReadableBuffer,
@@ -68,6 +68,14 @@ object ValueDocument {
}
}
+/**
+ * Extracts values of BSON array as list.
+ * @see ValueDocument
+ */
+object ValueList {
+ def unapply(arr: BSONArray): Option[List[BSONValue]] = Some(arr.values.toList)
+}
+
/**
* Request body extractor.
*
@@ -1,6 +1,6 @@
package acolyte.reactivemongo
-import reactivemongo.bson.{ BSONDocument, BSONDouble, BSONInteger, BSONString }
+import reactivemongo.bson.{ BSONArray, BSONDocument, BSONDouble, BSONInteger, BSONString }
object RequestSpec extends org.specs2.mutable.Specification
with RequestFixtures {
@@ -317,6 +317,15 @@ object RequestSpec extends org.specs2.mutable.Specification
}
}
}
+
+ "Array" should {
+ "be extracted as list values" in {
+ BSONArray("a", 2, 3.45d) aka "array" must beLike {
+ case ValueList(BSONString(a) :: BSONInteger(b) ::
+ BSONDouble(c) :: Nil) ok
+ }
+ }
+ }
}
sealed trait RequestFixtures {

0 comments on commit b663965

Please sign in to comment.