Created
April 26, 2012 09:28
-
-
Save vhazrati/2498069 to your computer and use it in GitHub Desktop.
SalatCustomContext Remapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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