Skip to content

Commit

Permalink
Fix adding new properties to lists with special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Nov 20, 2024
1 parent 4810d08 commit e742585
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
entities.forEach { entity ->
val existing = if (listExists) {
query(
list,
"\"$list\"",
"${EntitiesTable.COLUMN_ID} = ?",
arrayOf(entity.id)
).first { mapCursorRowToEntity(it, 0) }
Expand All @@ -92,7 +92,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
}

update(
list,
"\"$list\"",
contentValues,
"${EntitiesTable.COLUMN_ID} = ?",
arrayOf(entity.id)
Expand Down Expand Up @@ -390,7 +390,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
missingColumns.forEach {
execSQL(
"""
ALTER TABLE $list ADD "$it" text NOT NULL DEFAULT "";
ALTER TABLE "$list" ADD "$it" text NOT NULL DEFAULT "";
""".trimIndent()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,31 @@ abstract class EntitiesRepositoryTest {
assertThat(wines[0].properties, contains("window" to "2019-2038", "score" to "92"))
}

@Test
fun `#save adds new properties for lists with dashes`() {
val repository = buildSubject()

val wine = Entity.New(
"1",
"Léoville Barton 2008",
properties = listOf("window" to "2019-2038"),
version = 1
)
repository.save("favourite-wines", wine)

val updatedWine = Entity.New(
wine.id,
"Léoville Barton 2008",
properties = listOf("score" to "92"),
version = 2
)
repository.save("favourite-wines", updatedWine)

val wines = repository.getEntities("favourite-wines")
assertThat(wines.size, equalTo(1))
assertThat(wines[0].properties, contains("window" to "2019-2038", "score" to "92"))
}

@Test
fun `#save adds new properties to existing entities`() {
val repository = buildSubject()
Expand Down

0 comments on commit e742585

Please sign in to comment.