Fix list field bugs #45

Merged
merged 1 commit into from Jun 28, 2012
View
2 build.sbt
@@ -1,6 +1,6 @@
name := "slashem"
-version := "0.13.0"
+version := "0.13.1"
organization := "com.foursquare"
View
6 src/main/scala/com/foursquare/slashem/Schema.scala
@@ -1264,6 +1264,10 @@ class LongListField[T <: Record[T]](override val owner: T) extends Field[List[Lo
case "" => Empty
case ar: Array[Long] => Full(set(ar.toList))
case ar: Array[Integer] => Full(set(ar.toList.map(x => x.longValue)))
+ case ar: ArrayList[_] => Full(set(ar.toArray.asInstanceOf[Array[_]].toList.map(x =>{ x match {
+ case i: Integer => i.toLong
+ case l: Long => l
+ }})))
case s: String => Full(set(s.split(" ").map(x => x.toLong).toList))
case _ => Empty
}
@@ -1301,6 +1305,7 @@ class ObjectIdListField[T <: Record[T]](override val owner: T) extends Field[Lis
case "" => Empty
case ar: Array[ObjectId] => Full(ar.toList)
case ar: Array[String] => Full(ar.toList.map(x => new ObjectId(x)))
+ case ar: ArrayList[_] => Full(set(ar.toArray.toList.map(x => new ObjectId(x.asInstanceOf[String]))))
case s: String => Full(s.split(" ").map(x => new ObjectId(x)).toList)
case _ => Empty
}
@@ -1342,6 +1347,7 @@ class StringListField[T <: Record[T]](override val owner: T) extends Field[List[
case "" => Empty
case arr: Array[String] => Full(arr.toList)
case str: String => setFromString(str)
+ case ar: ArrayList[_] => Full(set(ar.toArray.toList.map(x => x.asInstanceOf[String])))
case _ => Empty
}
} catch {
View
17 src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
@@ -355,12 +355,27 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
@Test
def testIntListFieldReturn {
- val response1 = ESimplePanda where (_.favnums contains 2) fetch()
+ val response1 = ESimplePanda where (_.favnums contains 2) and (_.favnums contains 5) fetch()
Assert.assertEquals(response1.response.results.length, 2)
Assert.assertEquals(response1.response.results.head.favnums.get, List(1,2,3,4,5))
}
@Test
+ def testLongListFieldReturn {
+ val response = ESimplePanda where (_.hugenums contains 9L) fetch()
+ Assert.assertEquals(response.response.results.length, 1)
+ Assert.assertEquals(response.response.results.head.hugenums.get, List(1L, 9L, 8L))
+ }
+
+ @Test
+ def testObjectIdListFieldReturn {
+ val response = ESimplePanda where (_.favvenueids contains new ObjectId("4daf213893a0096fbaaef003")) fetch()
+ val venueids1 = List("4daf213893a0096fbaaef003", "49ee02e9f964a52010681fe3", "42b21280f964a5206d251fe3")
+ Assert.assertEquals(response.response.results.length, 1)
+ Assert.assertEquals(response.response.results.head.favvenueids.get, venueids1)
+ }
+
+ @Test
def testListFieldIn {
val response1 = ESimplePanda where (_.favnums in List(2, 3, 4, 5)) fetch()
val response2 = ESimplePanda where (_.favnums in List(99)) fetch()