@@ -2281,6 +2281,37 @@ final class MigrationTests: XCTestCase {
22812281 let insertedResource = try XCTUnwrap ( targetContext. first ( entityName: " BookingResource " ) )
22822282 XCTAssertEqual ( insertedResource, resource)
22832283 }
2284+
2285+ func test_migrating_from_128_to_129_adds_new_attendanceStatusKey_attribute_to_booking( ) throws {
2286+ // Given
2287+ let sourceContainer = try startPersistentContainer ( " Model 128 " )
2288+ let sourceContext = sourceContainer. viewContext
2289+
2290+ let booking = insertBooking ( to: sourceContext)
2291+ try sourceContext. save ( )
2292+
2293+ XCTAssertNil ( booking. entity. attributesByName [ " attendanceStatusKey " ] , " Precondition. Attribute does not exist. " )
2294+
2295+ // When
2296+ let targetContainer = try migrate ( sourceContainer, to: " Model 129 " )
2297+
2298+ // Then
2299+ let targetContext = targetContainer. viewContext
2300+ let migratedBooking = try XCTUnwrap ( targetContext. first ( entityName: " Booking " ) )
2301+
2302+ // `attendanceStatusKey` should be present in `migratedBooking`
2303+ XCTAssertNotNil ( migratedBooking. entity. attributesByName [ " attendanceStatusKey " ] )
2304+
2305+ // `attendanceStatusKey` value should default as nil in model 129
2306+ let value = migratedBooking. value ( forKey: " attendanceStatusKey " ) as? String
2307+ XCTAssertNil ( value)
2308+
2309+ // `attendanceStatusKey` must be settable
2310+ migratedBooking. setValue ( " checked_in " , forKey: " attendanceStatusKey " )
2311+ try targetContext. save ( )
2312+ let updatedValue = migratedBooking. value ( forKey: " attendanceStatusKey " ) as? String
2313+ XCTAssertEqual ( updatedValue, " checked_in " )
2314+ }
22842315}
22852316
22862317// MARK: - Persistent Store Setup and Migrations
0 commit comments