Fix failing test for FetchedRecordsController: when the request changes, we now do update the tracked tables and columns

This commit is contained in:
Gwendal Roué committed 2016-10-17 13:34:46 +02:00
1 parent f2cd90a999
commit 34b7cda2ec
2 files changed
+17 -1

No files matched your search

+16 -1
View File
@@ -350,7 +350,22 @@ public final class FetchedRecordsController<Record: RowConvertible> {
fileprivate var request: FetchRequest {
didSet {
guard let observer = observer else { return }
databaseWriter.writeForIssue117 { _ in
// If some changes are currently processed, make sure they are
// discarded. But preserve eventual changes processing.
let checkForChanges = observer.checkForChanges
observer.invalidate()
self.observer = nil
// Replace observer so that it tracks a new set of columns,
// and notify eventual changes
let initialItems = fetchedItems
databaseWriter.writeForIssue117 { db in
let (statement, _) = try! request.prepare(db)
let observer = FetchedRecordsObserver(readInfo: statement.readInfo, checkForChanges: checkForChanges)
self.observer = observer
observer.items = initialItems
db.add(transactionObserver: observer)
observer.performChangesChecking()
}
}
@@ -476,6 +476,7 @@ class FetchedRecordsControllerTests: GRDBTestCase {
XCTAssertEqual(recorder.recordsAfterChanges.count, 2)
XCTAssertEqual(recorder.recordsAfterChanges.map { $0.name }, ["Arthur", "Barbara"])
recorder.transactionExpectation = expectation(description: "expectation")
try dbQueue.inTransaction { db in
try db.execute("UPDATE persons SET email = ? WHERE name = ?", arguments: ["arthur@example.com", "Arthur"])
return .commit