diff --git a/Tests/IGListExperimentalAdapterE2ETests.m b/Tests/IGListExperimentalAdapterE2ETests.m index 82097089..dd26700f 100644 --- a/Tests/IGListExperimentalAdapterE2ETests.m +++ b/Tests/IGListExperimentalAdapterE2ETests.m @@ -1976,4 +1976,30 @@ [self waitForExpectationsWithTimeout:30 handler:nil]; } +- (void)test_whenUpdating_withMissingSectionController_thatDoesNotCrash { + [self setupWithObjects:@[ + genTestObject(@0, @"Foo"), + genTestObject(@1, @"Bar") + ]]; + + // Adding an object that won't have a corresponding section-controller + self.dataSource.objects = @[ + genTestObject(@0, @"Foo"), + genTestObject(@1, @"Bar"), + kIGTestDelegateDataSourceSkipObject + ]; + + // Perform updates on the adapter + XCTestExpectation *expectation = genExpectation; + [self.adapter performUpdatesAnimated:NO completion:^(BOOL finished) { + // Checked that the update worked + XCTAssertTrue(finished); + // Check that we skipped the object with a missing section-controller + XCTAssertEqual([self.collectionView numberOfSections], 2); + XCTAssertEqual(self.adapter.objects.count, 2); + [expectation fulfill]; + }]; + [self waitForExpectationsWithTimeout:30 handler:nil]; +} + @end diff --git a/Tests/Objects/IGTestDelegateDataSource.h b/Tests/Objects/IGTestDelegateDataSource.h index 6c3e8d9c..e33c860a 100644 --- a/Tests/Objects/IGTestDelegateDataSource.h +++ b/Tests/Objects/IGTestDelegateDataSource.h @@ -14,6 +14,8 @@ @class IGTestDelegateController; @class IGTestObject; +extern NSObject *const kIGTestDelegateDataSourceSkipObject; + @interface IGTestDelegateDataSource : NSObject @property (nonatomic, copy) NSArray *objects; diff --git a/Tests/Objects/IGTestDelegateDataSource.m b/Tests/Objects/IGTestDelegateDataSource.m index 57664fe3..84a4197c 100644 --- a/Tests/Objects/IGTestDelegateDataSource.m +++ b/Tests/Objects/IGTestDelegateDataSource.m @@ -12,6 +12,8 @@ #import "IGTestDelegateController.h" #import "IGTestObject.h" +NSObject *const kIGTestDelegateDataSourceSkipObject = @"kIGTestDelegateDataSourceSkipObject"; + @implementation IGTestDelegateDataSource - (NSArray *)objectsForListAdapter:(IGListAdapter *)listAdapter { @@ -19,6 +21,9 @@ } - (IGListSectionController *)listAdapter:(IGListAdapter *)listAdapter sectionControllerForObject:(id)object { + if ([object isEqual:kIGTestDelegateDataSourceSkipObject]) { + return nil; + } IGTestDelegateController *sectionController = [[IGTestDelegateController alloc] init]; sectionController.cellConfigureBlock = self.cellConfigureBlock; return sectionController;