Skip to content

Commit 91088d0

Browse files
committed
update tests that rely on state from removed models
1 parent 65144c7 commit 91088d0

File tree

2 files changed

+18
-35
lines changed

2 files changed

+18
-35
lines changed

Modules/Tests/StorageTests/CoreData/CoreDataIterativeMigrator+MigrationStepTests.swift

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ final class CoreDataIterativeMigrator_MigrationStepTests: XCTestCase {
2424

2525
func test_steps_returns_MigrationSteps_from_source_to_the_target_model() throws {
2626
// Given
27-
let modelVersion23 = ModelVersion(name: "Model 23")
28-
let modelVersion31 = ModelVersion(name: "Model 31")
27+
let modelVersion23 = ModelVersion(name: "Model 33")
28+
let modelVersion31 = ModelVersion(name: "Model 41")
2929
let sourceModel = try XCTUnwrap(modelsInventory.model(for: modelVersion23))
3030
let targetModel = try XCTUnwrap(modelsInventory.model(for: modelVersion31))
3131

@@ -34,18 +34,18 @@ final class CoreDataIterativeMigrator_MigrationStepTests: XCTestCase {
3434

3535
// Then
3636
// There should be 8 steps:
37-
// - 23 to 24
38-
// - 24 to 25
39-
// - 25 to 26
40-
// - 26 to 27
41-
// - 27 to 28
42-
// - 28 to 29
43-
// - 29 to 30
44-
// - 30 to 31
37+
// - 33 to 34
38+
// - 34 to 35
39+
// - 35 to 36
40+
// - 36 to 37
41+
// - 37 to 38
42+
// - 38 to 39
43+
// - 39 to 40
44+
// - 40 to 41
4545
XCTAssertEqual(steps.count, 8)
4646

4747
// Assert the values of first and last steps.
48-
let modelVersion24 = ModelVersion(name: "Model 24")
48+
let modelVersion24 = ModelVersion(name: "Model 34")
4949

5050
let expectedFirstStep = MigrationStep(sourceVersion: modelVersion23,
5151
sourceModel: try XCTUnwrap(modelsInventory.model(for: modelVersion23)),
@@ -54,7 +54,7 @@ final class CoreDataIterativeMigrator_MigrationStepTests: XCTestCase {
5454
let actualFirstStep = try XCTUnwrap(steps.first)
5555
XCTAssertEqual(actualFirstStep, expectedFirstStep)
5656

57-
let modelVersion30 = ModelVersion(name: "Model 30")
57+
let modelVersion30 = ModelVersion(name: "Model 40")
5858

5959
let expectedLastStep = MigrationStep(sourceVersion: modelVersion30,
6060
sourceModel: try XCTUnwrap(modelsInventory.model(for: modelVersion30)),
@@ -131,22 +131,4 @@ final class CoreDataIterativeMigrator_MigrationStepTests: XCTestCase {
131131
// Then
132132
assertEmpty(steps)
133133
}
134-
135-
/// If the `source` and `target` are the same models, `steps()` will return steps from **that**
136-
/// model version up to the latest version in the inventory.
137-
///
138-
/// This seems like a bug in the `steps()` loop that has existed for a long time. I would have
139-
/// expected that 0 steps are returned. I'm just keeping it as is for now. We don't
140-
/// reach this condition because of the precondition checks in `CoreDataIterativeMigrator`.
141-
func test_steps_returns_source_to_latest_version_MigrationSteps_if_the_source_and_target_are_the_same() throws {
142-
// Given
143-
let modelVersion37 = ModelVersion(name: "Model 37")
144-
let sourceModel = try XCTUnwrap(modelsInventory.model(for: modelVersion37))
145-
146-
// When
147-
let steps = try MigrationStep.steps(using: modelsInventory, source: sourceModel, target: sourceModel)
148-
149-
// Then
150-
XCTAssertEqual(steps.count, modelsInventory.versions.count - 37)
151-
}
152134
}

Modules/Tests/StorageTests/CoreData/CoreDataManagerTests.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ final class CoreDataManagerTests: XCTestCase {
184184
}
185185

186186
XCTAssertEqual(manager.viewStorage.countObjects(ofType: Account.self), 1)
187-
XCTAssertNotNil(NSEntityDescription.entity(forEntityName: Note.entityName,
187+
XCTAssertNotNil(NSEntityDescription.entity(forEntityName: OrderFeeLine.entityName,
188188
in: manager.viewStorage as! NSManagedObjectContext))
189189

190190
// When
@@ -193,8 +193,8 @@ final class CoreDataManagerTests: XCTestCase {
193193
// recreate the database.
194194
let invalidModelsInventory = ManagedObjectModelsInventory(
195195
packageURL: modelsInventory.packageURL,
196-
currentModel: try XCTUnwrap(modelsInventory.model(for: .init(name: "Model 2"))),
197-
versions: [.init(name: "Model 2")]
196+
currentModel: try XCTUnwrap(modelsInventory.model(for: .init(name: "Model 30"))),
197+
versions: [.init(name: "Model 30")]
198198
)
199199

200200
manager = try makeManager(using: invalidModelsInventory, deletingExistingStoreFiles: false)
@@ -211,8 +211,9 @@ final class CoreDataManagerTests: XCTestCase {
211211
insertAccount(to: manager.viewStorage)
212212
XCTAssertEqual(manager.viewStorage.countObjects(ofType: Account.self), 2)
213213

214-
// The Note entity does not exist in Model 2. This proves that the store was reset to Model 2.
215-
XCTAssertNil(NSEntityDescription.entity(forEntityName: Note.entityName,
214+
// The OrderFeeLine entity does not exist in Model 30, was introduced in Model 42
215+
// This proves that the store was reset to Model 30.
216+
XCTAssertNil(NSEntityDescription.entity(forEntityName: OrderFeeLine.entityName,
216217
in: manager.viewStorage as! NSManagedObjectContext))
217218
}
218219

0 commit comments

Comments
 (0)