Skip to content

Commit

Permalink
Merge pull request #6569 from grzesiek2010/COLLECT-6568
Browse files Browse the repository at this point in the history
Fixed reading properties from lists with special characters
  • Loading branch information
seadowg authored Jan 21, 2025
2 parents 8c76211 + c663beb commit 41b5cc6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
}
}

override fun clear() {
databaseConnection.withConnection {
dropAllTablesFromDB(writableDatabase)
}
}

override fun addList(list: String) {
if (!listExists(list)) {
createList(list)
Expand Down Expand Up @@ -232,7 +226,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
}

val propertyExists = databaseConnection.withConnection {
readableDatabase.doesColumnExist(list, EntitiesTable.getPropertyColumn(property))
readableDatabase.doesColumnExist(quote(list), EntitiesTable.getPropertyColumn(property))
}

return if (propertyExists) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,27 +313,6 @@ abstract class EntitiesRepositoryTest {
assertThat(repository.getEntities("favourite.wines")[0], sameEntityAs(wine))
}

@Test
fun `#clear deletes all entities`() {
val repository = buildSubject()

val wine = Entity.New("1", "Léoville Barton 2008")
val whisky = Entity.New("2", "Lagavulin 16")
repository.save("wines", wine)
repository.save("whiskys", whisky)

repository.clear()
assertThat(repository.getLists().size, equalTo(0))
assertThat(repository.getEntities("wines").size, equalTo(0))
assertThat(repository.getEntities("whiskys").size, equalTo(0))

repository.addList("wines")
assertThat(repository.getEntities("wines").size, equalTo(0))

repository.addList("whiskys")
assertThat(repository.getEntities("whiskys").size, equalTo(0))
}

@Test
fun `#save can save multiple entities`() {
val repository = buildSubject()
Expand Down Expand Up @@ -537,7 +516,7 @@ abstract class EntitiesRepositoryTest {
}

@Test
fun `#getByAllByProperty returns entities with matching property value`() {
fun `#getAllByProperty returns entities with matching property value`() {
val repository = buildSubject()

val leoville = Entity.New(
Expand All @@ -562,7 +541,7 @@ abstract class EntitiesRepositoryTest {
}

@Test
fun `#getByAllByProperty returns entities without property when searching for empty string`() {
fun `#getAllByProperty returns entities without property when searching for empty string`() {
val repository = buildSubject()

val leoville = Entity.New(
Expand All @@ -586,7 +565,7 @@ abstract class EntitiesRepositoryTest {
}

@Test
fun `#getByAllByProperty returns entities when searching for empty string for property that doesn't exist`() {
fun `#getAllByProperty returns entities when searching for empty string for property that doesn't exist`() {
val repository = buildSubject()

val leoville = Entity.New(
Expand All @@ -600,7 +579,7 @@ abstract class EntitiesRepositoryTest {
}

@Test
fun `#getByAllByProperty returns empty list when searching for non empty string for property that doesn't exist`() {
fun `#getAllByProperty returns empty list when searching for non empty string for property that doesn't exist`() {
val repository = buildSubject()

val leoville = Entity.New(
Expand Down Expand Up @@ -659,6 +638,32 @@ abstract class EntitiesRepositoryTest {
assertThat(repository.getAllByProperty("wines", "vintage", "1983"), equalTo(emptyList()))
}

@Test
fun `#getAllByProperty supports list names with dots and dashes`() {
val repository = buildSubject()

val leoville = Entity.New(
"1",
"Léoville Barton 2008",
properties = listOf("vintage" to "2008")
)

repository.save("favourite-wines", leoville)
repository.save("favourite.wines", leoville)

var wines = repository.getEntities("favourite-wines")
assertThat(
repository.getAllByProperty("favourite-wines", "vintage", "2008"),
containsInAnyOrder(wines.first { it.id == "1" })
)

wines = repository.getEntities("favourite.wines")
assertThat(
repository.getAllByProperty("favourite.wines", "vintage", "2008"),
containsInAnyOrder(wines.first { it.id == "1" })
)
}

@Test
fun `#getCount returns 0 when a list is empty`() {
val repository = buildSubject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,4 @@ class EntitiesViewModel(

return result
}

fun clearAll() {
scheduler.immediate {
entitiesRepository.clear()
_lists.postValue(entitiesRepository.getLists().toList())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ interface EntitiesRepository {
fun getLists(): Set<String>
fun getEntities(list: String): List<Entity.Saved>
fun getCount(list: String): Int
fun clear()
fun addList(list: String)
fun delete(id: String)
fun getById(list: String, id: String): Entity.Saved?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class InMemEntitiesRepository : EntitiesRepository {
return getEntities(list).count()
}

override fun clear() {
entities.clear()
lists.clear()
}

override fun addList(list: String) {
lists.add(list)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,6 @@ private class MeasurableEntitiesRepository(private val wrapped: EntitiesReposito
return wrapped.getCount(list)
}

override fun clear() {
accesses += 1
wrapped.clear()
}

override fun addList(list: String) {
accesses += 1
wrapped.addList(list)
Expand Down

0 comments on commit 41b5cc6

Please sign in to comment.