Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
added: test for forceInsertQuery fixes
- Loading branch information
Mateusz Kołodziejczyk
committed
Apr 26, 2016
1 parent
d00eaf7
commit bf5561253182017d676d42d171cb27828bd9723a
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
} | ||
} |