Skip to content

Instantly share code, notes, and snippets.

@Tapac
Created March 15, 2018 07:38
Show Gist options
  • Save Tapac/2518c19cbeefc6be6e56cfa850ed18db to your computer and use it in GitHub Desktop.
Save Tapac/2518c19cbeefc6be6e56cfa850ed18db to your computer and use it in GitHub Desktop.
Test for defaultExpression with updates
@Test
fun testDefaultExpressions02() {
val foo = object : IntIdTable("foo") {
val name = text("name")
val defaultDateTime = datetime("defaultDateTime").defaultExpression(CurrentDateTime())
}
val nonDefaultDate = DateTime.parse("2000-01-01")
withTables(foo) {
val id = foo.insertAndGetId {
it[foo.name] = "bar"
it[foo.defaultDateTime] = nonDefaultDate
}
val result = foo.select { foo.id eq id }.single()
assertEquals("bar", result[foo.name])
assertEquals(nonDefaultDate.millis, result[foo.defaultDateTime].withTimeAtStartOfDay().millis)
foo.update({foo.id eq id}) {
it[foo.name] = "baz"
}
val result2 = foo.select { foo.id eq id }.single()
assertEquals("baz", result2[foo.name])
assertEquals(nonDefaultDate, result2[foo.defaultDateTime].withTimeAtStartOfDay())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment