Skip to content

Instantly share code, notes, and snippets.

@vhazrati
Created April 26, 2012 09:28

Revisions

  1. Vikas Hazrati created this gist Apr 26, 2012.
    27 changes: 27 additions & 0 deletions SalatCustomContext
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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"))
    19 changes: 19 additions & 0 deletions customcontext
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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")
    }