FetchedRecordsController: tests that trackChanges { ... } trailing closure is invoked after records have been changed.

This commit is contained in:
Gwendal Roué committed 2016-05-11 10:45:48 +02:00
1 parent 1d5999e50b
commit fbb40e1232
2 files changed
+44

No files matched your search

@@ -435,6 +435,28 @@ class FetchedRecordsControllerOSXTests: GRDBTestCase {
XCTAssertEqual(recorder.recordsAfterChanges.map { $0.name }, ["Arthur"])
}
}
func testTrailingClosureCallback() {
assertNoError {
let dbQueue = try makeDatabaseQueue()
let controller = FetchedRecordsController<Person>(dbQueue, request: Person.order(SQLColumn("name")), compareRecordsByPrimaryKey: true)
var persons: [Person] = []
controller.performFetch()
let expectation = expectationWithDescription("expectation")
controller.trackChanges {
persons = $0.fetchedRecords!
expectation.fulfill()
}
try dbQueue.inTransaction { db in
try synchronizePersons(db, [
Person(id: 1, name: "Arthur")])
return .Commit
}
waitForExpectationsWithTimeout(1, handler: nil)
XCTAssertEqual(persons.map { $0.name }, ["Arthur"])
}
}
}
@@ -693,6 +693,28 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase {
}
}
}
func testTrailingClosureCallback() {
assertNoError {
let dbQueue = try makeDatabaseQueue()
let controller = FetchedRecordsController<Person>(dbQueue, request: Person.order(SQLColumn("name")), compareRecordsByPrimaryKey: true)
var persons: [Person] = []
controller.performFetch()
let expectation = expectationWithDescription("expectation")
controller.trackChanges {
persons = $0.fetchedRecords!
expectation.fulfill()
}
try dbQueue.inTransaction { db in
try synchronizePersons(db, [
Person(id: 1, name: "Arthur")])
return .Commit
}
waitForExpectationsWithTimeout(1, handler: nil)
XCTAssertEqual(persons.map { $0.name }, ["Arthur"])
}
}
}