@@ -2755,6 +2755,32 @@ final class MigrationTests: XCTestCase {
27552755 let updatedCategory = migratedLabel. value ( forKey: " hazmatCategory " ) as? String
27562756 XCTAssertEqual ( updatedCategory, category)
27572757 }
2758+
2759+ func test_migrating_126_to_127_adds_new_booking_entity( ) throws {
2760+ // Given
2761+ let sourceContainer = try startPersistentContainer ( " Model 126 " )
2762+ let sourceContext = sourceContainer. viewContext
2763+
2764+ try sourceContext. save ( )
2765+
2766+ // Confidence Check. Booking should not exist in Model 126
2767+ XCTAssertNil ( NSEntityDescription . entity ( forEntityName: " Booking " , in: sourceContext) )
2768+
2769+ // When
2770+ let targetContainer = try migrate ( sourceContainer, to: " Model 127 " )
2771+ let targetContext = targetContainer. viewContext
2772+
2773+ // Then
2774+ XCTAssertEqual ( try targetContext. count ( entityName: " Booking " ) , 0 )
2775+
2776+ let booking = insertBooking ( to: targetContext)
2777+ XCTAssertNoThrow ( try targetContext. save ( ) )
2778+
2779+ XCTAssertEqual ( try targetContext. count ( entityName: " Booking " ) , 1 )
2780+ let insertedBooking = try XCTUnwrap ( targetContext. firstObject ( ofType: Booking . self) )
2781+ XCTAssertEqual ( insertedBooking, booking)
2782+ XCTAssertEqual ( insertedBooking. parentID, 0 ) // default value
2783+ }
27582784}
27592785
27602786// MARK: - Persistent Store Setup and Migrations
@@ -3679,4 +3705,12 @@ private extension MigrationTests {
36793705 " id " : " test-address "
36803706 ] )
36813707 }
3708+
3709+ @discardableResult
3710+ func insertBooking( to context: NSManagedObjectContext ) -> NSManagedObject {
3711+ context. insert ( entityName: " Booking " , properties: [
3712+ " siteID " : 1 ,
3713+ " bookingID " : 23
3714+ ] )
3715+ }
36823716}
0 commit comments