Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix DateTimeZoneSpec by adding an explicit extractor that serializes …

…a DateTimeZone as its ID.

Conflicts:
	salat-core/src/test/scala/com/novus/salat/test/DateTimeZoneSpec.scala
  • Loading branch information...
commit a3f38d82ed79bb098e3906f562d0cc1a180a0b31 1 parent 7e91107
@rktoomey rktoomey authored
View
24 salat-core/src/main/scala/com/novus/salat/transformers/extract/Extractors.scala
@@ -1,9 +1,9 @@
/*
- * Copyright (c) 2010 - 2012 Novus Partners, Inc. (http://www.novus.com)
+ * Copyright (c) 2010 - 2013 Novus Partners, Inc. (http://www.novus.com)
*
* Module: salat-core
* Class: Extractors.scala
- * Last modified: 2012-10-15 20:40:58 EDT
+ * Last modified: 2013-01-07 22:59:22 EST
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,6 +51,9 @@ package object out {
case TypeRefType(_, symbol, _) if isFloat(symbol.path) =>
new Transformer(symbol.path, t)(ctx) with OptionExtractor with FloatToDouble
+ case TypeRefType(_, symbol, _) if isJodaDateTimeZone(symbol.path) =>
+ new Transformer(symbol.path, t)(ctx) with OptionExtractor with DateTimeZoneExtractor
+
case t @ TypeRefType(prefix @ SingleType(_, esym), sym, _) if sym.path == "scala.Enumeration.Value" => {
new Transformer(prefix.symbol.path, t)(ctx) with OptionExtractor with EnumStringifier
}
@@ -80,6 +83,9 @@ package object out {
case TypeRefType(_, symbol, _) if isChar(symbol.path) =>
new Transformer(symbol.path, t)(ctx) with CharToString with TraversableExtractor
+ case TypeRefType(_, symbol, _) if isJodaDateTimeZone(symbol.path) =>
+ new Transformer(symbol.path, t)(ctx) with DateTimeZoneExtractor with TraversableExtractor
+
case t @ TypeRefType(prefix @ SingleType(_, esym), sym, _) if sym.path == "scala.Enumeration.Value" => {
new Transformer(prefix.symbol.path, t)(ctx) with EnumStringifier with TraversableExtractor
}
@@ -107,6 +113,9 @@ package object out {
case TypeRefType(_, symbol, _) if isChar(symbol.path) =>
new Transformer(symbol.path, t)(ctx) with CharToString with MapExtractor
+ case TypeRefType(_, symbol, _) if isJodaDateTimeZone(symbol.path) =>
+ new Transformer(symbol.path, t)(ctx) with DateTimeZoneExtractor with MapExtractor
+
case TypeRefType(_, symbol, _) if isFloat(symbol.path) =>
new Transformer(symbol.path, t)(ctx) with FloatToDouble with MapExtractor
@@ -133,6 +142,9 @@ package object out {
case TypeRefType(_, symbol, _) if isChar(symbol.path) =>
new Transformer(symbol.path, t)(ctx) with CharToString
+ case TypeRefType(_, symbol, _) if isJodaDateTimeZone(symbol.path) =>
+ new Transformer(symbol.path, t)(ctx) with DateTimeZoneExtractor
+
case TypeRefType(_, symbol, _) if isFloat(symbol.path) =>
new Transformer(symbol.path, t)(ctx) with FloatToDouble
@@ -238,6 +250,14 @@ package out {
}
}
+ trait DateTimeZoneExtractor extends Transformer {
+ override def transform(value: Any)(implicit ctx: Context) = value match {
+ case tz: org.joda.time.DateTimeZone => Some(tz.getID)
+ case tz: java.util.TimeZone => Some(tz.getID)
+ case _ => None
+ }
+ }
+
trait MapExtractor extends Transformer {
self: Transformer =>
override def transform(value: Any)(implicit ctx: Context): Any = value
View
17 salat-core/src/test/scala/com/novus/salat/test/DateTimeZoneSpec.scala
@@ -1,9 +1,9 @@
/*
- * Copyright (c) 2010 - 2012 Novus Partners, Inc. (http://www.novus.com)
+ * Copyright (c) 2010 - 2013 Novus Partners, Inc. (http://www.novus.com)
*
* Module: salat-core
- * Class: DateTimeSpec.scala
- * Last modified: 2012-10-15 20:40:58 EDT
+ * Class: DateTimeZoneSpec.scala
+ * Last modified: 2013-01-07 23:00:06 EST
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,24 +24,23 @@
*/
package com.novus.salat.test
+import com.mongodb.casbah.Imports._
+import com.mongodb.util.JSON.parse
import com.novus.salat._
import com.novus.salat.test.global._
import com.novus.salat.test.model._
-
-import com.mongodb.casbah.Imports._
-import com.mongodb.util.JSON.parse
+import org.joda.time.DateTimeZone
class DateTimeZoneSpec extends SalatSpec {
"A grater" should {
"support org.scala_tools.time.TypeImports.DateTimeZone" in {
- import org.scala_tools.time.Imports._
val tz = DateTimeZone.forID("Europe/London")
val n = Prue(zone = tz)
val dbo: MongoDBObject = grater[Prue].asDBObject(n)
// log.info(MapPrettyPrinter(dbo))
dbo must havePair("_typeHint", "com.novus.salat.test.model.Prue")
dbo must havePair("brawl" -> true)
- dbo must havePair("zone", tz)
+ dbo must havePair("zone", tz.getID)
val coll = MongoConnection()(SalatSpecDb)("scala_timezone_test_1")
val wr = coll.insert(dbo)
@@ -56,7 +55,7 @@ class DateTimeZoneSpec extends SalatSpec {
// log.info(MapPrettyPrinter(dbo))
dbo must havePair("_typeHint", "com.novus.salat.test.model.Prue")
dbo must havePair("brawl" -> true)
- dbo must havePair("zone", tz)
+ dbo must havePair("zone", tz.getID)
val coll = MongoConnection()(SalatSpecDb)("scala_timezone_test_2")
val wr = coll.insert(dbo)
Please sign in to comment.
Something went wrong with that request. Please try again.