Skip to content

Commit

Permalink
more thorough BigDecimal conversions & test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxaf committed Sep 5, 2010
1 parent 39c9ef3 commit 3874bd8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion casbah-mapper/src/main/scala/mapper/Mapper.scala
Expand Up @@ -478,7 +478,8 @@ abstract class Mapper[P <: AnyRef : Manifest]() extends Logging with OJ {
case s: String if prop.id_? && idProp.map(_.autoId_?).getOrElse(false) => new ObjectId(s)
case d: Double if prop.innerType == classOf[JavaBigDecimal] => new JavaBigDecimal(d, MATH_CONTEXT)
case d: Double if prop.innerType == classOf[ScalaBigDecimal] => ScalaBigDecimal(d, MATH_CONTEXT)
case d: java.lang.Double if prop.innerType == classOf[ScalaBigDecimal] => ScalaBigDecimal(d.asInstanceOf[scala.Double], MATH_CONTEXT)
case x if prop.innerType == classOf[ScalaBigDecimal] => ScalaBigDecimal(x.toString, MATH_CONTEXT)
case x if prop.innerType == classOf[JavaBigDecimal] => new JavaBigDecimal(x.toString, MATH_CONTEXT)
case _ => v
}) match {
case x if x != null && prop.option_? => Some(x)
Expand Down
8 changes: 8 additions & 0 deletions casbah-mapper/src/test/scala/MapperSpec.scala
Expand Up @@ -71,6 +71,9 @@ class Piggy(@Key val giggity: String) {
@Key
var balance: Option[BigDecimal] = None

@Key("days_in_year")
var daysInYear: Option[BigDecimal] = None

@Key
var freshness: Freshness.Value = Freshness.Fresh
}
Expand Down Expand Up @@ -266,6 +269,7 @@ class MapperSpec extends Specification with PendingUntilFixed with Logging {
val POLITICAL_VIEWS = Map("wikileaks" -> "is my favorite site", "democrats" -> "have ruined the economy")
val FAMILY = Map("father" -> new Piggy("father"), "mother" -> new Piggy("mother"))
val BALANCE = BigDecimal("0.12345678901234")
val DAYS_IN_YEAR = BigDecimal("365")

val before = new Chair

Expand All @@ -275,6 +279,7 @@ class MapperSpec extends Specification with PendingUntilFixed with Logging {
piggy.political_views = POLITICAL_VIEWS
piggy.family = FAMILY
piggy.balance = Some(BALANCE)
piggy.daysInYear = Some(DAYS_IN_YEAR)
piggy.freshness = Freshness.Stale
before.optional_piggy = Some(piggy)
before.things = Set("foo", "bar", "baz", "quux", "foo", "baz")
Expand All @@ -296,6 +301,9 @@ class MapperSpec extends Specification with PendingUntilFixed with Logging {
piggy.balance must beSome[BigDecimal].which {
b => b must_== BALANCE
}
piggy.daysInYear must beSome[BigDecimal].which {
b => b must_== DAYS_IN_YEAR
}
piggy.freshness must_== Freshness.Stale
}
after.always_here must beSome[String]
Expand Down

0 comments on commit 3874bd8

Please sign in to comment.