Skip to content

Commit 4d7ce1d

Browse files
authored
Merge pull request #478 from morganchen12/master
Fix bad loop behavior on invalidation in FUIArray, add tests
2 parents 7e184af + 6999ded commit 4d7ce1d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

FirebaseDatabaseUI/FUIArray.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ - (void)invalidate {
161161

162162
// Remove all values on invalidation.
163163
[self didUpdate];
164-
for (NSInteger i = 0; i < self.snapshots.count; i++) {
164+
for (NSInteger i = 0; i < self.snapshots.count; /* no i++ since we modify the array instead*/ ) {
165165
FIRDataSnapshot *current = self.snapshots[i];
166166

167167
[self.snapshots removeObjectAtIndex:i];
@@ -269,7 +269,7 @@ - (id)objectAtIndexedSubscript:(NSUInteger)index {
269269
return [self snapshotAtIndex:index];
270270
}
271271

272-
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index{
272+
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index {
273273
@throw [NSException exceptionWithName:@"FUIArraySetIndexWithSubscript"
274274
reason:@"Setting an object as FUIArray[i] is not supported."
275275
userInfo:nil];

FirebaseDatabaseUITests/FUIArrayTest.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,4 +476,13 @@ - (void)testArraySendsMessagesAfterReceivingValueEvent {
476476
XCTAssert(ended == 1, @"expected array to end updates exactly once");
477477
}
478478

479+
- (void)testRemovesAllElementsWhenInvalidated {
480+
[self.observable populateWithCount:10];
481+
[self.firebaseArray invalidate];
482+
483+
XCTAssert(self.firebaseArray.count == 0,
484+
@"Expected array to be empty after invalidation, instead got %ld elements",
485+
self.firebaseArray.count);
486+
}
487+
479488
@end

0 commit comments

Comments
 (0)