mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Tests for FetchedRecordsController error handling
This commit is contained in:
1 parent
ed4826a67f
commit
c4e04d6e07
2 files changed
+32
-1
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
- [ ] Request.bound(to:adapter:) (requires adapters to be able to adapt an already adapted row)
|
||||
- [ ] Think about supporting Cursor's underestimatedCount, which could speed up Array(cursor) and fetchAll()
|
||||
- [ ] FetchedRecordsController: handle fetch errors
|
||||
- [ ] FetchedRecordsController: document how to handle errors
|
||||
- [ ] Swift 3.0.2 (Xcode 8.2): "Type inference will properly unwrap optionals when used with generics and implicitly-unwrapped optionals." Maybe this fixes `row.value(named: "foo") as? Int`?
|
||||
- [ ] Attach databases (this could be the support for fetched records controller caches). Interesting question: what happens when one attaches a non-WAL db to a databasePool?
|
||||
- [ ] SQLCipher: sqlite3_rekey is discouraged (https://github.com/ccgus/fmdb/issues/547#issuecomment-259219320)
|
||||
|
||||
@@ -591,6 +591,37 @@ class FetchedRecordsControllerTests: GRDBTestCase {
|
||||
XCTAssertEqual(recorder.countAfterChanges!, 2)
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchErrors() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let controller = try FetchedRecordsController<Person>(dbQueue, request: Person.all())
|
||||
|
||||
let expectation = self.expectation(description: "expectation")
|
||||
var error: Error?
|
||||
controller.trackErrors {
|
||||
error = $1
|
||||
expectation.fulfill()
|
||||
}
|
||||
controller.trackChanges { _ in }
|
||||
try controller.performFetch()
|
||||
try dbQueue.inTransaction { db in
|
||||
try synchronizePersons(db, [
|
||||
Person(id: 1, name: "Arthur")])
|
||||
try db.drop(table: "persons")
|
||||
return .commit
|
||||
}
|
||||
waitForExpectations(timeout: 1, handler: nil)
|
||||
if let error = error as? DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: persons")
|
||||
XCTAssertEqual(error.sql!, "SELECT * FROM \"persons\"")
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `SELECT * FROM \"persons\"`: no such table: persons")
|
||||
} else {
|
||||
XCTFail("Expected DatabaseError")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user