Skip to content

Instantly share code, notes, and snippets.

@vhazrati
Created April 26, 2012 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vhazrati/2498069 to your computer and use it in GitHub Desktop.
Save vhazrati/2498069 to your computer and use it in GitHub Desktop.
SalatCustomContext Remapping
import com.novus.salat._
import com.mongodb.casbah.Imports._
/**
* We are overriding the global context of Salat to change the default behaviour of
* typehinting. See https://github.com/novus/salat/wiki/CustomContext
*/
package object custom_type_hint {
implicit val ctx = new Context {
/** name of the overriding context */
val name = "Context-TypeHintNever"
/** override the default typehinting strategy */
override val typeHintStrategy = NeverTypeHint
}
// Renaming the default _id to id
ctx.registerGlobalKeyOverride(remapThis = "_id", toThisInstead = "id")
}
import org.scalatest.FunSuite
import com.novus.salat.annotations.Key
import org.bson.types.ObjectId
import org.specs2.specification.BeforeAfter
import org.scalatest.BeforeAndAfter
import com.novus.salat.dao.SalatDAO
import com.mongodb.casbah.MongoConnection
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
//import com.novus.salat.global._
import com.mongodb.casbah.Imports._
import com.codahale.jerkson.Json
import com.twelvekd.aggregator.server.utils.custom_type_hint._
@RunWith(classOf[JUnitRunner])
class ExperienceOfferRecordTest extends FunSuite with BeforeAndAfter {
test("Check that Salat saves the object to MongoDB with single id") {
val vikas = Vikas(title="HipHopppp")
VikasDAO.insert(vikas)
}
}
case class Vikas(title: String)
object VikasDAO extends SalatDAO[Vikas, ObjectId](collection = MongoConnection()("12kd")("vikas"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment