mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
FetchedRecordsController: tests that trackChanges { ... } trailing closure is invoked after records have been changed.
This commit is contained in:
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"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user