Skip to content

Commit

Permalink
test changed properties for reference binding
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlauvlwj committed Jul 8, 2024
1 parent 5fdd30e commit fb0c257
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ktorm-core/src/test/kotlin/org/ktorm/entity/EntityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,28 @@ class EntityTest : BaseTest() {
assert(p2.flushChanges() == 1)
}

@Test
fun testChangedPropertiesForReferenceBinding() {
val e = database.employees.find { it.id eq 1 } ?: throw AssertionError()
e.name = "Vincent"
e.job = "Senior Engineer"
e.job = "Expert Engineer"
e.manager = database.employees.find { it.id eq 2 }
e.manager = database.employees.find { it.id eq 2 }
e.salary = 999999
e.department = database.departments.find { it.id eq 2 } ?: throw AssertionError()
e.department = database.departments.find { it.id eq 2 } ?: throw AssertionError()

val changed = e.changedProperties
assert(changed.size == 5)
assert(changed["name"] == "vince")
assert(changed["job"] == "engineer")
assert(changed["manager"].toString() == "Employee(id=null)")
assert(changed["salary"] == 100L)
assert(changed["department"].toString() == "Department(id=1)")
assert(e.flushChanges() == 1)
}

@Test
fun testHasColumnValue() {
val p1 = Parent()
Expand Down

0 comments on commit fb0c257

Please sign in to comment.