PersistenceController tests
This commit is contained in:
parent
cde82d956b
commit
b8b7e1f913
4 changed files with 112 additions and 7 deletions
|
|
@ -18,19 +18,19 @@ public class PersistenceController {
|
|||
|
||||
let container: NSPersistentContainer
|
||||
|
||||
init(isUnitTest: Bool = false) {
|
||||
init(storeURL: URL? = nil) {
|
||||
self.container = NSPersistentContainer(name: Self.modelName, managedObjectModel: .sharedModel)
|
||||
let description = container.persistentStoreDescriptions.first
|
||||
description?.shouldMigrateStoreAutomatically = false
|
||||
description?.shouldInferMappingModelAutomatically = false
|
||||
if isUnitTest {
|
||||
description?.url = URL(fileURLWithPath: "/dev/null")
|
||||
} else {
|
||||
description?.url = URL(fileURLWithPath: Globals.dbPath)
|
||||
}
|
||||
description?.url = storeURL ?? URL(fileURLWithPath: Globals.dbPath)
|
||||
setup()
|
||||
}
|
||||
|
||||
static func forUnitTests() -> PersistenceController {
|
||||
PersistenceController(storeURL: URL(fileURLWithPath: "/dev/null"))
|
||||
}
|
||||
|
||||
func setup() {
|
||||
container.loadPersistentStores { _, error in
|
||||
if error != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue