Permalink
Browse files

added: test for forceInsertQuery fixes

  • Loading branch information...
1 parent d00eaf7 commit bf5561253182017d676d42d171cb27828bd9723a @coutoPL coutoPL committed Apr 26, 2016
@@ -46,6 +46,7 @@ testkit {
${testPackage}.TransactionTest
${testPackage}.UnionTest
${testPackage}.ForUpdateTest
+ ${testPackage}.ForceInsertQueryTest
]
}
@@ -0,0 +1,45 @@
+package com.typesafe.slick.testkit.tests
+
+import com.typesafe.slick.testkit.util.{AsyncTest, JdbcTestDB}
+
+class ForceInsertQueryTest extends AsyncTest[JdbcTestDB] {
+
+ import tdb.profile.api._
+
+ case class Person(id: Option[Long] = None,
+ name: Option[String] = None,
+ hairColor: Option[String] = None,
+ eyeColor: Option[String] = None)
+
+ class People(tag: Tag) extends Table[Person](tag, "people") {
+ def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
+
+ def name = column[Option[String]]("name")
+
+ def hairColor = column[Option[String]]("hair_color")
+
+ def eyeColor = column[Option[String]]("eye_color")
+
+ def * = (id.?, name, hairColor, eyeColor) <>(Person.tupled, Person.unapply)
+ }
+
+ object peopleTable extends TableQuery(new People(_)) {
+ def someForcedInsert(person: Person) = {
+ this.map(p => (p.name, p.hairColor, p.eyeColor))
+ .forceInsertQuery {
+ Query((person.name, person.hairColor, person.eyeColor))
+ }
+ }
+ }
+
+ def testForceInsert = {
+ DBIO.seq(
+ peopleTable.schema.create,
+ peopleTable.someForcedInsert(Person(name = Some("John"), hairColor = Some("Brown"), eyeColor = Some("Brown"))),
+ peopleTable.someForcedInsert(Person(name = Some("John"), hairColor = None, eyeColor = None)),
+ peopleTable.someForcedInsert(Person(name = None, hairColor = None, eyeColor = None)),
+ peopleTable.someForcedInsert(Person(name = Some("John"), hairColor = None, eyeColor = Some("Blue"))),
+ peopleTable.schema.drop
+ )
+ }
+}

0 comments on commit bf55612

Please sign in to comment.