From abce41d6fd6e361e2f94ba37fc6bb63278a50394 Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Tue, 15 Mar 2011 19:53:14 -0700 Subject: [PATCH] Make sure -[CPArrayController arrangedObjects] always has a non-nil value. --- AppKit/CPArrayController.j | 2 +- Tests/AppKit/CPArrayControllerTest.j | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/AppKit/CPArrayController.j b/AppKit/CPArrayController.j index c465aa4d8..6d3f92abf 100644 --- a/AppKit/CPArrayController.j +++ b/AppKit/CPArrayController.j @@ -136,7 +136,7 @@ _sortDescriptors = [CPArray array]; _filterPredicate = nil; _selectionIndexes = [CPIndexSet indexSet]; - _arrangedObjects = nil; + _arrangedObjects = [CPArray array]; } - (void)prepareContent diff --git a/Tests/AppKit/CPArrayControllerTest.j b/Tests/AppKit/CPArrayControllerTest.j index 84506e5a8..b83b580e1 100644 --- a/Tests/AppKit/CPArrayControllerTest.j +++ b/Tests/AppKit/CPArrayControllerTest.j @@ -56,6 +56,24 @@ [self assert:object equals:[[arrayController arrangedObjects] objectAtIndex:1]]; } +- (void)testAddObjectUpdatesArrangedObjectsWithoutSortDescriptors +{ + var arrayController = [[CPArrayController alloc] init]; + + [arrayController addObject:@"content"]; + [self assert:[@"content"] equals:[arrayController content]]; + [self assert:[@"content"] equals:[arrayController arrangedObjects]]; +} + +- (void)testInsertObjectUpdatesArrangedObjectsWithoutSortDescriptors +{ + var arrayController = [[CPArrayController alloc] init]; + + [arrayController insertObject:@"content" atArrangedObjectIndex:0]; + [self assert:[@"content"] equals:[arrayController content]]; + [self assert:[@"content"] equals:[arrayController arrangedObjects]]; +} + - (void)testSelectPrevious { var arrayController = [self arrayController];