Skip to content
Browse files

Cleanups to and test coverage expansion of RKTableController API's. r…

…efs #765
  • Loading branch information...
1 parent 680ca66 commit 59c449c2e282160b5570b66abd70954aaee9bead @blakewatters blakewatters committed May 24, 2012
View
31 Code/Testing/RKTableControllerTestDelegate.h
@@ -0,0 +1,31 @@
+//
+// RKTableControllerTestDelegate.h
+// RestKit
+//
+// Created by Blake Watters on 5/23/12.
+// Copyright (c) 2012 RestKit. All rights reserved.
+//
+
+#if TARGET_OS_IPHONE
+#import "RKTableController.h"
+#import "RKFetchedResultsTableController.h"
+
+@interface RKAbstractTableControllerTestDelegate : NSObject <RKAbstractTableControllerDelegate>
+
+@property(nonatomic, readonly, getter = isCancelled) BOOL cancelled;
+@property(nonatomic, assign) NSTimeInterval timeout;
+@property(nonatomic, assign) BOOL awaitingResponse;
+
++ (id)tableControllerDelegate;
+- (void)waitForLoad;
+
+@end
+
+@interface RKTableControllerTestDelegate : RKAbstractTableControllerTestDelegate <RKTableControllerDelegate>
+@end
+
+@interface RKFetchedResultsTableControllerTestDelegate : RKAbstractTableControllerTestDelegate <RKFetchedResultsTableControllerDelegate>
+
+@end
+
+#endif
View
139 Code/Testing/RKTableControllerTestDelegate.m
@@ -0,0 +1,139 @@
+//
+// RKTableControllerTestDelegate.m
+// RestKit
+//
+// Created by Blake Watters on 5/23/12.
+// Copyright (c) 2012 RestKit. All rights reserved.
+//
+
+#import "RKTableControllerTestDelegate.h"
+#import "RKLog.h"
+
+#if TARGET_OS_IPHONE
+
+@implementation RKAbstractTableControllerTestDelegate
+
+@synthesize timeout = _timeout;
+@synthesize awaitingResponse = _awaitingResponse;
+@synthesize cancelled = _cancelled;
+
++ (id)tableControllerDelegate {
+ return [[self new] autorelease];
+}
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ _timeout = 1.0;
+ _awaitingResponse = NO;
+ _cancelled = NO;
+ }
+
+ return self;
+}
+
+- (void)waitForLoad {
+ _awaitingResponse = YES;
+ NSDate *startDate = [NSDate date];
+
+ while (_awaitingResponse) {
+ RKLogTrace(@"Awaiting response = %d", _awaitingResponse);
+ [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
+ if ([[NSDate date] timeIntervalSinceDate:startDate] > self.timeout) {
+ NSLog(@"%@: Timed out!!!", self);
+ _awaitingResponse = NO;
+ [NSException raise:nil format:@"*** Operation timed out after %f seconds...", self.timeout];
+ }
+ }
+}
+
+#pragma RKTableControllerDelegate methods
+
+- (void)tableControllerDidFinishLoad:(RKAbstractTableController *)tableController {
+ _awaitingResponse = NO;
+}
+
+- (void)tableController:(RKAbstractTableController*)tableController didFailLoadWithError:(NSError *)error {
+ _awaitingResponse = NO;
+}
+
+- (void)tableControllerDidCancelLoad:(RKAbstractTableController *)tableController {
+ _awaitingResponse = NO;
+ _cancelled = YES;
+}
+
+- (void)tableControllerDidFinalizeLoad:(RKAbstractTableController *)tableController {
+ _awaitingResponse = NO;
+}
+
+// NOTE - Delegate methods below are implemented to allow trampoline through
+// OCMock expectations
+
+- (void)tableControllerDidStartLoad:(RKAbstractTableController *)tableController
+{}
+
+- (void)tableControllerDidBecomeEmpty:(RKAbstractTableController *)tableController
+{}
+
+- (void)tableController:(RKAbstractTableController *)tableController willLoadTableWithObjectLoader:(RKObjectLoader *)objectLoader
+{}
+
+- (void)tableController:(RKAbstractTableController *)tableController didLoadTableWithObjectLoader:(RKObjectLoader *)objectLoader
+{}
+
+- (void)tableController:(RKAbstractTableController*)tableController willBeginEditing:(id)object atIndexPath:(NSIndexPath*)indexPath
+{}
+
+- (void)tableController:(RKAbstractTableController*)tableController didEndEditing:(id)object atIndexPath:(NSIndexPath*)indexPath
+{}
+
+- (void)tableController:(RKAbstractTableController*)tableController didInsertSection:(RKTableSection*)section atIndex:(NSUInteger)sectionIndex
+{}
+
+- (void)tableController:(RKAbstractTableController*)tableController didRemoveSection:(RKTableSection*)section atIndex:(NSUInteger)sectionIndex
+{}
+
+- (void)tableController:(RKAbstractTableController*)tableController didInsertObject:(id)object atIndexPath:(NSIndexPath*)indexPath
+{}
+
+- (void)tableController:(RKAbstractTableController*)tableController didUpdateObject:(id)object atIndexPath:(NSIndexPath*)indexPath
+{}
+
+- (void)tableController:(RKAbstractTableController*)tableController didDeleteObject:(id)object atIndexPath:(NSIndexPath*)indexPath
+{}
+
+- (void)tableController:(RKAbstractTableController*)tableController willAddSwipeView:(UIView*)swipeView toCell:(UITableViewCell*)cell forObject:(id)object
+{}
+
+- (void)tableController:(RKAbstractTableController*)tableController willRemoveSwipeView:(UIView*)swipeView fromCell:(UITableViewCell*)cell forObject:(id)object
+{}
+
+- (void)tableController:(RKTableController *)tableController didLoadObjects:(NSArray *)objects inSection:(NSUInteger)sectionIndex
+{}
+
+- (void)tableController:(RKAbstractTableController *)tableController willDisplayCell:(UITableViewCell *)cell forObject:(id)object atIndexPath:(NSIndexPath *)indexPath
+{}
+
+- (void)tableController:(RKAbstractTableController *)tableController didSelectCell:(UITableViewCell *)cell forObject:(id)object atIndexPath:(NSIndexPath *)indexPath
+{}
+
+@end
+
+@implementation RKTableControllerTestDelegate
+
+- (void)tableController:(RKTableController *)tableController didLoadObjects:(NSArray *)objects inSection:(RKTableSection *)section
+{}
+
+@end
+
+@implementation RKFetchedResultsTableControllerTestDelegate
+
+- (void)tableController:(RKFetchedResultsTableController *)tableController didInsertSectionAtIndex:(NSUInteger)sectionIndex
+{}
+
+- (void)tableController:(RKFetchedResultsTableController *)tableController didDeleteSectionAtIndex:(NSUInteger)sectionIndex
+{}
+
+@end
+
+#endif
View
13 Code/UI/RKAbstractTableController.h
@@ -152,6 +152,7 @@ typedef NSUInteger RKTableControllerState;
*/
- (NSIndexPath *)indexPathForObject:(id)object;
- (UITableViewCell *)cellForObject:(id)object;
+- (void)reloadRowForObject:(id)object withRowAnimation:(UITableViewRowAnimation)rowAnimation;
///-----------------------------------------------------------------------------
/// @name Header and Footer Rows
@@ -399,7 +400,6 @@ typedef NSUInteger RKTableControllerState;
- (void)tableControllerDidFinishLoad:(RKAbstractTableController *)tableController;
- (void)tableController:(RKAbstractTableController *)tableController didFailLoadWithError:(NSError *)error;
- (void)tableControllerDidCancelLoad:(RKAbstractTableController *)tableController;
-- (void)tableController:(RKAbstractTableController *)tableController didLoadObjects:(NSArray *)objects inSection:(NSUInteger)sectionIndex; // NOT IMPLEMENTED
/**
Sent to the delegate when the controller is really and truly finished loading/updating, whether from the network or from Core Data,
@@ -422,11 +422,6 @@ typedef NSUInteger RKTableControllerState;
*/
- (void)tableControllerDidBecomeOffline:(RKAbstractTableController *)tableController;
-// Sections
-// TODO: Can these even be implemented???
-- (void)tableController:(RKAbstractTableController *)tableController didInsertSectionAtIndex:(NSUInteger)sectionIndex;
-- (void)tableController:(RKAbstractTableController *)tableController didRemoveSectionAtIndex:(NSUInteger)sectionIndex;
-
// Objects
- (void)tableController:(RKAbstractTableController *)tableController didInsertObject:(id)object atIndexPath:(NSIndexPath *)indexPath;
- (void)tableController:(RKAbstractTableController *)tableController didUpdateObject:(id)object atIndexPath:(NSIndexPath *)indexPath;
@@ -440,16 +435,10 @@ typedef NSUInteger RKTableControllerState;
- (void)tableController:(RKAbstractTableController *)tableController willAddSwipeView:(UIView *)swipeView toCell:(UITableViewCell *)cell forObject:(id)object;
- (void)tableController:(RKAbstractTableController *)tableController willRemoveSwipeView:(UIView *)swipeView fromCell:(UITableViewCell *)cell forObject:(id)object;
-// BELOW NOT YET IMPLEMENTED
-
// Cells
- (void)tableController:(RKAbstractTableController *)tableController willDisplayCell:(UITableViewCell *)cell forObject:(id)object atIndexPath:(NSIndexPath *)indexPath;
- (void)tableController:(RKAbstractTableController *)tableController didSelectCell:(UITableViewCell *)cell forObject:(id)object atIndexPath:(NSIndexPath *)indexPath;
-// Objects
-- (void)tableControllerDidBeginUpdates:(RKAbstractTableController *)tableController;
-- (void)tableControllerDidEndUpdates:(RKAbstractTableController *)tableController;
-
@end
#endif // TARGET_OS_IPHONE
View
43 Code/UI/RKAbstractTableController.m
@@ -112,7 +112,7 @@ - (id)initWithTableView:(UITableView *)theTableView viewController:(UIViewContro
self = [self init];
if (self) {
self.tableView = theTableView;
- self.viewController = theViewController;
+ _viewController = theViewController; // Assign directly to avoid side-effect of overloaded accessor method
self.variableHeightRows = NO;
self.defaultRowAnimation = UITableViewRowAnimationFade;
self.overlayFrame = CGRectZero;
@@ -201,8 +201,6 @@ - (void)setTableView:(UITableView *)tableView {
}
- (void)setViewController:(UIViewController *)viewController {
- _viewController = viewController;
-
if ([viewController isKindOfClass:[UITableViewController class]]) {
self.tableView = [(UITableViewController*)viewController tableView];
}
@@ -466,6 +464,10 @@ - (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPa
RKLogTrace(@"%@: Invoking onSelectCellForObjectAtIndexPath block with cellMapping %@ for object %@ at indexPath = %@", self, cell, object, indexPath);
cellMapping.onSelectCellForObjectAtIndexPath(cell, object, indexPath);
}
+
+ if ([self.delegate respondsToSelector:@selector(tableController:didSelectCell:forObject:atIndexPath:)]) {
+ [self.delegate tableController:self didSelectCell:cell forObject:object atIndexPath:indexPath];
+ }
}
- (void)tableView:(UITableView *)theTableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -476,6 +478,10 @@ - (void)tableView:(UITableView *)theTableView willDisplayCell:(UITableViewCell *
if (cellMapping.onCellWillAppearForObjectAtIndexPath) {
cellMapping.onCellWillAppearForObjectAtIndexPath(cell, mappableObject, indexPath);
}
+
+ if ([self.delegate respondsToSelector:@selector(tableController:willDisplayCell:forObject:atIndexPath:)]) {
+ [self.delegate tableController:self willDisplayCell:cell forObject:mappableObject atIndexPath:indexPath];
+ }
// Informal protocol
// TODO: Needs documentation!!!
@@ -633,7 +639,7 @@ - (BOOL)isAutoRefreshNeeded {
- (void)requestDidStartLoad:(RKRequest *)request {
RKLogTrace(@"tableController %@ started loading.", self);
- self.loading = YES;
+ [self didStartLoad];
}
- (void)requestDidCancelLoad:(RKRequest *)request {
@@ -673,8 +679,7 @@ - (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error {
RKLogError(@"tableController %@ failed network load with error: %@", self, error);
- self.error = error;
- [self didFinishLoad];
+ [self didFailLoadWithError:error];
}
- (void)objectLoaderDidFinishLoading:(RKObjectLoader *)objectLoader {
@@ -686,13 +691,26 @@ - (void)objectLoaderDidFinishLoading:(RKObjectLoader *)objectLoader {
[self didFinishLoad];
}
+- (void)didStartLoad {
+ self.loading = YES;
+}
+
+- (void)didFailLoadWithError:(NSError *)error {
+ self.error = error;
+ [self didFinishLoad];
+}
+
- (void)didFinishLoad {
self.empty = [self isConsideredEmpty];
self.loading = [self.objectLoader isLoading]; // Mutate loading state after we have adjusted empty
self.loaded = YES;
-
- if (self.delegate && [_delegate respondsToSelector:@selector(tableControllerDidFinalizeLoad:)]) {
- [_delegate performSelector:@selector(tableControllerDidFinalizeLoad:) withObject:self];
+
+ if (![self isEmpty] && ![self isLoading]) {
+ [[NSNotificationCenter defaultCenter] postNotificationName:RKTableControllerDidLoadObjectsNotification object:self];
+ }
+
+ if (self.delegate && [_delegate respondsToSelector:@selector(tableControllerDidFinalizeLoad:)]) {
+ [self.delegate performSelector:@selector(tableControllerDidFinalizeLoad:) withObject:self];
}
}
@@ -1319,4 +1337,11 @@ - (void)loadTableWithObjectLoader:(RKObjectLoader *)theObjectLoader {
}
}
+- (void)reloadRowForObject:(id)object withRowAnimation:(UITableViewRowAnimation)rowAnimation {
+ NSIndexPath *indexPath = [self indexPathForObject:object];
+ if (indexPath) {
+ [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:rowAnimation];
+ }
+}
+
@end
View
13 Code/UI/RKAbstractTableController_Internals.h
@@ -38,13 +38,18 @@
@property (nonatomic, readonly) RKCache *cache;
@property (nonatomic, retain) UIView *pullToRefreshHeaderView;
+#pragma mark - Subclass Load Event Hooks
+
+- (void)didStartLoad;
+
/**
Must be invoked when the table controller has finished loading.
Responsible for finalizing loading, empty, and loaded states
and cleaning up the table overlay view.
*/
- (void)didFinishLoad;
+- (void)didFailLoadWithError:(NSError *)error;
#pragma mark - Table View Overlay
@@ -60,14 +65,6 @@
- (void)pullToRefreshStateChanged:(UIGestureRecognizer *)gesture;
- (void)resetPullToRefreshRecognizer;
-#pragma mark - State Mutators
-
-- (void)setLoading:(BOOL)loading;
-- (void)setLoaded:(BOOL)loaded;
-- (void)setEmpty:(BOOL)empty;
-- (void)setOffline:(BOOL)offline;
-- (void)setErrorState:(BOOL)error;
-
/**
Returns a Boolean value indicating if the table controller
should be considered empty and transitioned into the empty state.
View
12 Code/UI/RKFetchedResultsTableController.h
@@ -22,6 +22,17 @@
typedef UIView *(^RKFetchedResultsTableViewViewForHeaderInSectionBlock)(NSUInteger sectionIndex, NSString *sectionTitle);
+@class RKFetchedResultsTableController;
+@protocol RKFetchedResultsTableControllerDelegate <RKAbstractTableControllerDelegate>
+
+@optional
+
+// Sections
+- (void)tableController:(RKFetchedResultsTableController *)tableController didInsertSectionAtIndex:(NSUInteger)sectionIndex;
+- (void)tableController:(RKFetchedResultsTableController *)tableController didDeleteSectionAtIndex:(NSUInteger)sectionIndex;
+
+@end
+
/**
Instances of RKFetchedResultsTableController provide an interface for driving a UITableView
*/
@@ -33,6 +44,7 @@ typedef UIView *(^RKFetchedResultsTableViewViewForHeaderInSectionBlock)(NSUInteg
BOOL _isEmptyBeforeAnimation;
}
+@property (nonatomic, assign) id<RKFetchedResultsTableControllerDelegate> delegate;
@property (nonatomic, retain, readonly) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, copy) NSString *resourcePath;
@property (nonatomic, retain) NSFetchRequest *fetchRequest;
View
57 Code/UI/RKFetchedResultsTableController.m
@@ -17,6 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
+
#import "RKFetchedResultsTableController.h"
#import "RKAbstractTableController_Internals.h"
#import "RKManagedObjectStore.h"
@@ -33,12 +34,13 @@
@interface RKFetchedResultsTableController ()
@property (nonatomic, retain, readwrite) NSFetchedResultsController *fetchedResultsController;
-- (void)performFetch;
+- (BOOL)performFetch:(NSError **)error;
- (void)updateSortedArray;
@end
@implementation RKFetchedResultsTableController
+@dynamic delegate;
@synthesize fetchedResultsController = _fetchedResultsController;
@synthesize resourcePath = _resourcePath;
@synthesize heightForHeaderInSection = _heightForHeaderInSection;
@@ -77,19 +79,31 @@ - (void)dealloc {
#pragma mark - Helpers
-- (void)performFetch {
+- (BOOL)performFetch:(NSError **)error {
// TODO: We could be doing a KVO on the predicate/sortDescriptors/sectionKeyPath and intelligently deleting the cache
[NSFetchedResultsController deleteCacheWithName:_fetchedResultsController.cacheName];
-
- NSError* error;
- BOOL success = [_fetchedResultsController performFetch:&error];
+ BOOL success = [_fetchedResultsController performFetch:error];
if (!success) {
- self.error = error;
- RKLogError(@"performFetch failed with error: %@", [error localizedDescription]);
+ RKLogError(@"performFetch failed with error: %@", [*error localizedDescription]);
+ return NO;
} else {
RKLogTrace(@"performFetch completed successfully");
- [[NSNotificationCenter defaultCenter] postNotificationName:RKTableControllerDidLoadObjectsNotification object:self];
+ for (NSUInteger index = 0; index < [self sectionCount]; index++) {
+ if ([self.delegate respondsToSelector:@selector(tableController:didInsertSectionAtIndex:)]) {
+ [self.delegate tableController:self didInsertSectionAtIndex:index];
+ }
+
+ if ([self.delegate respondsToSelector:@selector(tableController:didInsertObject:atIndexPath:)]) {
+ for (NSUInteger row = 0; row < [self numberOfRowsInSection:index]; row++) {
+ NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:index];
+ id object = [self objectForRowAtIndexPath:indexPath];
+ [self.delegate tableController:self didInsertObject:object atIndexPath:indexPath];
+ }
+ }
+ }
}
+
+ return YES;
}
- (void)updateSortedArray {
@@ -238,10 +252,14 @@ - (void)loadTable {
[_fetchedResultsController release];
_fetchedResultsController.delegate = self;
-
- [self performFetch];
+ // Perform the load
+ NSError *error;
+ [self didStartLoad];
+ BOOL success = [self performFetch:&error];
+ if (! success) {
+ [self didFailLoadWithError:error];
+ }
[self updateSortedArray];
-
[self.tableView reloadData];
[self didFinishLoad];
@@ -512,7 +530,7 @@ - (BOOL)isConsideredEmpty {
- (void)controllerWillChangeContent:(NSFetchedResultsController*)controller {
RKLogTrace(@"Beginning updates for fetchedResultsController (%@). Current section count = %d (resource path: %@)", controller, [[controller sections] count], _resourcePath);
- if(_sortSelector) return;
+ if (_sortSelector) return;
[self.tableView beginUpdates];
_isEmptyBeforeAnimation = [self isEmpty];
@@ -523,17 +541,25 @@ - (void)controller:(NSFetchedResultsController*)controller
atIndex:(NSUInteger)sectionIndex
forChangeType:(NSFetchedResultsChangeType)type {
- if(_sortSelector) return;
+ if (_sortSelector) return;
switch (type) {
case NSFetchedResultsChangeInsert:
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationFade];
+
+ if ([self.delegate respondsToSelector:@selector(tableController:didInsertSectionAtIndex:)]) {
+ [self.delegate tableController:self didInsertSectionAtIndex:sectionIndex];
+ }
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationFade];
+
+ if ([self.delegate respondsToSelector:@selector(tableController:didDeleteSectionAtIndex:)]) {
+ [self.delegate tableController:self didDeleteSectionAtIndex:sectionIndex];
+ }
break;
default:
@@ -548,7 +574,7 @@ - (void)controller:(NSFetchedResultsController*)controller
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
- if(_sortSelector) return;
+ if (_sortSelector) return;
NSIndexPath* adjIndexPath = [self indexPathForFetchedResultsIndexPath:indexPath];
NSIndexPath* adjNewIndexPath = [self indexPathForFetchedResultsIndexPath:newIndexPath];
@@ -595,13 +621,12 @@ - (void)controllerDidChangeContent:(NSFetchedResultsController*)controller {
[self updateSortedArray];
- if(_sortSelector) {
+ if (_sortSelector) {
[self.tableView reloadData];
} else {
[self.tableView endUpdates];
}
- [[NSNotificationCenter defaultCenter] postNotificationName:RKTableControllerDidLoadObjectsNotification object:self];
[self didFinishLoad];
}
View
8 Code/UI/RKTableController.h
@@ -33,8 +33,7 @@
@optional
-- (void)tableController:(RKAbstractTableController *)tableController didInsertSection:(RKTableSection *)section atIndex:(NSUInteger)sectionIndex;
-- (void)tableController:(RKAbstractTableController *)tableController didRemoveSection:(RKTableSection *)section atIndex:(NSUInteger)sectionIndex;
+- (void)tableController:(RKTableController *)tableController didLoadObjects:(NSArray *)objects inSection:(RKTableSection *)section;
@end
@@ -50,9 +49,6 @@
- (void)loadObjects:(NSArray *)objects inSection:(NSUInteger)sectionIndex;
- (void)loadEmpty;
-// Move to superclass???
-- (void)reloadRowForObject:(id)object withRowAnimation:(UITableViewRowAnimation)rowAnimation;
-
/**
Load an array of RKTableItems into table cells of the specified class. A table cell
mapping will be constructed on your behalf and yielded to the block for configuration.
@@ -134,7 +130,6 @@
Returns the first section with the specified header title.
@param title The header title.
*/
-// MOVED
- (RKTableSection *)sectionWithHeaderTitle:(NSString *)title;
/**
@@ -143,7 +138,6 @@
@param section Must be a valid non nil RKTableViewSection.
@return The index of the given section if contained within the receiver, otherwise NSNotFound.
*/
-// MOVED
- (NSUInteger)indexForSection:(RKTableSection *)section;
// Coalesces a series of table view updates performed within the block into
View
37 Code/UI/RKTableController.m
@@ -86,7 +86,7 @@ - (void)removeSectionsAtIndexes:(NSIndexSet *)indexes {
[self.sections removeObjectsAtIndexes:indexes];
}
-- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects {
+- (void)replaceSectionsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects {
[self.sections replaceObjectsAtIndexes:indexes withObjects:objects];
}
@@ -98,11 +98,6 @@ - (void)addSection:(RKTableSection *)section {
}
[[self sectionsProxy] addObject:section];
-
- // TODO: move into KVO?
- if ([self.delegate respondsToSelector:@selector(tableController:didInsertSection:atIndex:)]) {
- [self.delegate tableController:self didInsertSection:section atIndex:[self.sections indexOfObject:section]];
- }
}
- (void)removeSection:(RKTableSection *)section {
@@ -112,21 +107,13 @@ - (void)removeSection:(RKTableSection *)section {
reason:@"Tables must always have at least one section"
userInfo:nil];
}
- NSUInteger index = [self.sections indexOfObject:section];
- if ([self.delegate respondsToSelector:@selector(tableController:didRemoveSection:atIndex:)]) {
- [self.delegate tableController:self didRemoveSection:section atIndex:index];
- }
[[self sectionsProxy] removeObject:section];
}
- (void)insertSection:(RKTableSection *)section atIndex:(NSUInteger)index {
NSAssert(section, @"Cannot insert a nil section");
section.tableController = self;
[[self sectionsProxy] insertObject:section atIndex:index];
-
- if ([self.delegate respondsToSelector:@selector(tableController:didInsertSection:atIndex:)]) {
- [self.delegate tableController:self didInsertSection:section atIndex:index];
- }
}
- (void)removeSectionAtIndex:(NSUInteger)index {
@@ -135,21 +122,10 @@ - (void)removeSectionAtIndex:(NSUInteger)index {
reason:@"Tables must always have at least one section"
userInfo:nil];
}
- RKTableSection* section = [self.sections objectAtIndex:index];
- if ([self.delegate respondsToSelector:@selector(tableController:didRemoveSection:atIndex:)]) {
- [self.delegate tableController:self didRemoveSection:section atIndex:index];
- }
[[self sectionsProxy] removeObjectAtIndex:index];
}
- (void)removeAllSections:(BOOL)recreateFirstSection {
- NSUInteger sectionCount = [self.sections count];
- for (NSUInteger index = 0; index < sectionCount; index++) {
- RKTableSection* section = [self.sections objectAtIndex:index];
- if ([self.delegate respondsToSelector:@selector(tableController:didRemoveSection:atIndex:)]) {
- [self.delegate tableController:self didRemoveSection:section atIndex:index];
- }
- }
[[self sectionsProxy] removeAllObjects];
if (recreateFirstSection) {
@@ -204,7 +180,9 @@ - (void)loadObjects:(NSArray *)objects inSection:(NSUInteger)sectionIndex {
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:self.defaultRowAnimation];
- [[NSNotificationCenter defaultCenter] postNotificationName:RKTableControllerDidLoadObjectsNotification object:self];
+ if ([self.delegate respondsToSelector:@selector(tableController:didLoadObjects:inSection:)]) {
+ [self.delegate tableController:self didLoadObjects:objects inSection:section];
+ }
// The load is finalized via network callbacks for
// dynamic table controllers
@@ -348,13 +326,6 @@ - (void)objectLoader:(RKObjectLoader *)loader didLoadObjects:(NSArray *)objects
}
}
-- (void)reloadRowForObject:(id)object withRowAnimation:(UITableViewRowAnimation)rowAnimation {
- NSIndexPath *indexPath = [self indexPathForObject:object];
- if (indexPath) {
- [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:rowAnimation];
- }
-}
-
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
if ([keyPath isEqualToString:@"sections"]) {
View
12 RestKit.xcodeproj/project.pbxproj
@@ -675,6 +675,10 @@
25DB7509151BD551009F01AF /* NSManagedObject+ActiveRecordTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 25DB7507151BD551009F01AF /* NSManagedObject+ActiveRecordTest.m */; };
25E36E0215195CED00F9E448 /* RKFetchRequestMappingCacheTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 25E36E0115195CED00F9E448 /* RKFetchRequestMappingCacheTest.m */; };
25E36E0315195CED00F9E448 /* RKFetchRequestMappingCacheTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 25E36E0115195CED00F9E448 /* RKFetchRequestMappingCacheTest.m */; };
+ 25E4DAB4156DA97F00A5C84B /* RKTableControllerTestDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 25E4DAB2156DA97F00A5C84B /* RKTableControllerTestDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 25E4DAB5156DA97F00A5C84B /* RKTableControllerTestDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 25E4DAB2156DA97F00A5C84B /* RKTableControllerTestDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 25E4DAB6156DA97F00A5C84B /* RKTableControllerTestDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 25E4DAB3156DA97F00A5C84B /* RKTableControllerTestDelegate.m */; };
+ 25E4DAB7156DA97F00A5C84B /* RKTableControllerTestDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 25E4DAB3156DA97F00A5C84B /* RKTableControllerTestDelegate.m */; };
25EC1A2C14F6FDAD00C3CF3F /* RKObjectManager+RKTableController.h in Headers */ = {isa = PBXBuildFile; fileRef = 25EC1A2A14F6FDAC00C3CF3F /* RKObjectManager+RKTableController.h */; settings = {ATTRIBUTES = (Public, ); }; };
25EC1A2D14F6FDAD00C3CF3F /* RKObjectManager+RKTableController.h in Headers */ = {isa = PBXBuildFile; fileRef = 25EC1A2A14F6FDAC00C3CF3F /* RKObjectManager+RKTableController.h */; settings = {ATTRIBUTES = (Public, ); }; };
25EC1A2E14F6FDAD00C3CF3F /* RKObjectManager+RKTableController.m in Sources */ = {isa = PBXBuildFile; fileRef = 25EC1A2B14F6FDAC00C3CF3F /* RKObjectManager+RKTableController.m */; };
@@ -1173,6 +1177,8 @@
25CAAA9315254E7800CAE5D7 /* ArrayOfHumans.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ArrayOfHumans.json; sourceTree = "<group>"; };
25DB7507151BD551009F01AF /* NSManagedObject+ActiveRecordTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSManagedObject+ActiveRecordTest.m"; sourceTree = "<group>"; };
25E36E0115195CED00F9E448 /* RKFetchRequestMappingCacheTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKFetchRequestMappingCacheTest.m; sourceTree = "<group>"; };
+ 25E4DAB2156DA97F00A5C84B /* RKTableControllerTestDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RKTableControllerTestDelegate.h; path = Testing/RKTableControllerTestDelegate.h; sourceTree = "<group>"; };
+ 25E4DAB3156DA97F00A5C84B /* RKTableControllerTestDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RKTableControllerTestDelegate.m; path = Testing/RKTableControllerTestDelegate.m; sourceTree = "<group>"; };
25EC1A2A14F6FDAC00C3CF3F /* RKObjectManager+RKTableController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RKObjectManager+RKTableController.h"; sourceTree = "<group>"; };
25EC1A2B14F6FDAC00C3CF3F /* RKObjectManager+RKTableController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RKObjectManager+RKTableController.m"; sourceTree = "<group>"; };
25EC1AB814F8019F00C3CF3F /* RKRefreshGestureRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKRefreshGestureRecognizer.h; sourceTree = "<group>"; };
@@ -1974,6 +1980,8 @@
25055B8E14EEF40000B9C4DD /* RKMappingTestExpectation.m */,
252EFB2414D9B6F2004863C8 /* Testing.h */,
25C954A415542A47005C9E08 /* RKTestConstants.m */,
+ 25E4DAB2156DA97F00A5C84B /* RKTableControllerTestDelegate.h */,
+ 25E4DAB3156DA97F00A5C84B /* RKTableControllerTestDelegate.m */,
);
name = Testing;
sourceTree = "<group>";
@@ -2264,6 +2272,7 @@
259D98541550C69A008C90F5 /* RKEntityByAttributeCache.h in Headers */,
259D985E155218E5008C90F5 /* RKEntityCache.h in Headers */,
25545959155F0527007D7625 /* RKBenchmark.h in Headers */,
+ 25E4DAB4156DA97F00A5C84B /* RKTableControllerTestDelegate.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2388,6 +2397,7 @@
259D98551550C69A008C90F5 /* RKEntityByAttributeCache.h in Headers */,
259D985F155218E5008C90F5 /* RKEntityCache.h in Headers */,
2554595A155F0527007D7625 /* RKBenchmark.h in Headers */,
+ 25E4DAB5156DA97F00A5C84B /* RKTableControllerTestDelegate.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2796,6 +2806,7 @@
259D98561550C69A008C90F5 /* RKEntityByAttributeCache.m in Sources */,
259D9860155218E5008C90F5 /* RKEntityCache.m in Sources */,
2554595B155F0527007D7625 /* RKBenchmark.m in Sources */,
+ 25E4DAB6156DA97F00A5C84B /* RKTableControllerTestDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2985,6 +2996,7 @@
259D98571550C69A008C90F5 /* RKEntityByAttributeCache.m in Sources */,
259D9861155218E5008C90F5 /* RKEntityCache.m in Sources */,
2554595C155F0527007D7625 /* RKBenchmark.m in Sources */,
+ 25E4DAB7156DA97F00A5C84B /* RKTableControllerTestDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
373 Tests/Application/UI/RKFetchedResultsTableControllerTest.m
@@ -14,6 +14,7 @@
#import "RKEvent.h"
#import "RKAbstractTableController_Internals.h"
#import "RKManagedObjectCaching.h"
+#import "RKTableControllerTestDelegate.h"
// Expose the object loader delegate for testing purposes...
@interface RKFetchedResultsTableController () <RKObjectLoaderDelegate>
@@ -31,20 +32,21 @@ - (NSIndexPath*)fetchedResultsIndexPathForIndexPath:(NSIndexPath*)indexPath;
@end
-@interface RKFetchedResultsTableControllerSpecViewController : UIViewController
+@interface RKFetchedResultsTableControllerSpecViewController : UITableViewController
@end
@implementation RKFetchedResultsTableControllerSpecViewController
@end
@interface RKFetchedResultsTableControllerTest : RKTestCase
-
@end
@implementation RKFetchedResultsTableControllerTest
- (void)setUp {
[RKTestFactory setUp];
+
+ [[[[UIApplication sharedApplication] windows] objectAtIndex:0] setRootViewController:nil];
}
- (void)tearDown {
@@ -57,7 +59,7 @@ - (void)bootstrapStoreAndCache {
[humanMapping mapKeyPath:@"id" toAttribute:@"railsID"];
[humanMapping mapAttributes:@"name", nil];
humanMapping.primaryKeyAttribute = @"railsID";
-
+
[RKHuman truncateAll];
assertThatInt([RKHuman count:nil], is(equalToInt(0)));
RKHuman* blake = [RKHuman createEntity];
@@ -70,11 +72,11 @@ - (void)bootstrapStoreAndCache {
[store save:&error];
assertThat(error, is(nilValue()));
assertThatInt([RKHuman count:nil], is(equalToInt(2)));
-
+
RKObjectManager* objectManager = [RKTestFactory objectManager];
[objectManager.mappingProvider setMapping:humanMapping forKeyPath:@"human"];
objectManager.objectStore = store;
-
+
[objectManager.mappingProvider setObjectMapping:humanMapping forResourcePathPattern:@"/JSON/humans/all\\.json" withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) {
return [RKHuman requestAllSortedBy:@"name" ascending:YES];
}];
@@ -88,7 +90,7 @@ - (void)bootstrapNakedObjectStoreAndCache {
[eventMapping mapAttributes:@"location", @"summary", nil];
eventMapping.primaryKeyAttribute = @"eventID";
[RKEvent truncateAll];
-
+
assertThatInt([RKEvent count:nil], is(equalToInt(0)));
RKEvent *nakedEvent = [RKEvent createEntity];
nakedEvent.eventID = @"RK4424";
@@ -99,11 +101,11 @@ - (void)bootstrapNakedObjectStoreAndCache {
[store save:&error];
assertThat(error, is(nilValue()));
assertThatInt([RKEvent count:nil], is(equalToInt(1)));
-
+
RKObjectManager* objectManager = [RKTestFactory objectManager];
[objectManager.mappingProvider addObjectMapping:eventMapping];
objectManager.objectStore = store;
-
+
id mockMappingProvider = [OCMockObject partialMockForObject:objectManager.mappingProvider];
[[[mockMappingProvider stub] andReturn:[RKEvent requestAllSortedBy:@"eventType" ascending:YES]] fetchRequestForResourcePath:@"/JSON/NakedEvents.json"];
}
@@ -114,14 +116,14 @@ - (void)bootstrapEmptyStoreAndCache {
[humanMapping mapKeyPath:@"id" toAttribute:@"railsID"];
[humanMapping mapAttributes:@"name", nil];
humanMapping.primaryKeyAttribute = @"railsID";
-
+
[RKHuman truncateAll];
assertThatInt([RKHuman count:nil], is(equalToInt(0)));
-
+
RKObjectManager* objectManager = [RKTestFactory objectManager];
[objectManager.mappingProvider setMapping:humanMapping forKeyPath:@"human"];
objectManager.objectStore = store;
-
+
id mockMappingProvider = [OCMockObject partialMockForObject:objectManager.mappingProvider];
[[[mockMappingProvider stub] andReturn:[RKHuman requestAllSortedBy:@"name" ascending:YES]] fetchRequestForResourcePath:@"/JSON/humans/all.json"];
[[[mockMappingProvider stub] andReturn:[RKHuman requestAllSortedBy:@"name" ascending:YES]] fetchRequestForResourcePath:@"/empty/array"];
@@ -139,62 +141,52 @@ - (void)stubObjectManagerToOnline {
- (void)testLoadWithATableViewControllerAndResourcePath {
[self bootstrapStoreAndCache];
- UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
- RKFetchedResultsTableController* tableController =
- [[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ RKFetchedResultsTableController* tableController = [RKFetchedResultsTableController tableControllerForTableViewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController loadTable];
-
+
assertThat(tableController.viewController, is(equalTo(viewController)));
- assertThat(tableController.tableView, is(equalTo(tableView)));
+ assertThat(tableController.tableView, is(equalTo(viewController.tableView)));
assertThat(tableController.resourcePath, is(equalTo(@"/JSON/humans/all.json")));
}
- (void)testLoadWithATableViewControllerAndResourcePathFromNakedObjects {
[self bootstrapNakedObjectStoreAndCache];
- UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
- RKFetchedResultsTableController* tableController =
- [[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ RKFetchedResultsTableController* tableController = [RKFetchedResultsTableController tableControllerForTableViewController:viewController];
tableController.resourcePath = @"/JSON/NakedEvents.json";
[tableController setObjectMappingForClass:[RKEvent class]];
[tableController loadTable];
-
+
assertThat(tableController.viewController, is(equalTo(viewController)));
- assertThat(tableController.tableView, is(equalTo(tableView)));
+ assertThat(tableController.tableView, is(equalTo(viewController.tableView)));
assertThat(tableController.resourcePath, is(equalTo(@"/JSON/NakedEvents.json")));
-
+
RKTableViewCellMapping* cellMapping = [RKTableViewCellMapping mappingForClass:[UITableViewCell class]];
[cellMapping mapKeyPath:@"summary" toAttribute:@"textLabel.text"];
RKTableViewCellMappings* mappings = [RKTableViewCellMappings new];
[mappings setCellMapping:cellMapping forClass:[RKEvent class]];
tableController.cellMappings = mappings;
-
+
UITableViewCell* cell = [tableController tableView:tableController.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
assertThat(cell.textLabel.text, is(equalTo(@"Shindig")));
}
- (void)testLoadWithATableViewControllerAndResourcePathAndPredicateAndSortDescriptors {
[self bootstrapStoreAndCache];
- UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
NSPredicate* predicate = [NSPredicate predicateWithValue:TRUE];
NSArray* sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES]];
- RKFetchedResultsTableController* tableController =
- [[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ RKFetchedResultsTableController* tableController = [RKFetchedResultsTableController tableControllerForTableViewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.predicate = predicate;
tableController.sortDescriptors = sortDescriptors;
[tableController loadTable];
-
+
assertThat(tableController.viewController, is(equalTo(viewController)));
- assertThat(tableController.tableView, is(equalTo(tableView)));
assertThat(tableController.resourcePath, is(equalTo(@"/JSON/humans/all.json")));
assertThat(tableController.fetchRequest, is(notNilValue()));
assertThat([tableController.fetchRequest predicate], is(equalTo(predicate)));
@@ -203,18 +195,14 @@ - (void)testLoadWithATableViewControllerAndResourcePathAndPredicateAndSortDescri
- (void)testLoadWithATableViewControllerAndResourcePathAndSectionNameAndCacheName {
[self bootstrapStoreAndCache];
- UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
- RKFetchedResultsTableController* tableController =
- [[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ RKFetchedResultsTableController* tableController = [RKFetchedResultsTableController tableControllerForTableViewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.sectionNameKeyPath = @"name";
tableController.cacheName = @"allHumansCache";
[tableController loadTable];
-
+
assertThat(tableController.viewController, is(equalTo(viewController)));
- assertThat(tableController.tableView, is(equalTo(tableView)));
assertThat(tableController.resourcePath, is(equalTo(@"/JSON/humans/all.json")));
assertThat(tableController.fetchRequest, is(notNilValue()));
assertThat(tableController.fetchedResultsController.sectionNameKeyPath, is(equalTo(@"name")));
@@ -223,23 +211,19 @@ - (void)testLoadWithATableViewControllerAndResourcePathAndSectionNameAndCacheNam
- (void)testLoadWithAllParams {
[self bootstrapStoreAndCache];
- UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
NSPredicate* predicate = [NSPredicate predicateWithValue:TRUE];
NSArray* sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES]];
- RKFetchedResultsTableController* tableController =
- [[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ RKFetchedResultsTableController* tableController = [RKFetchedResultsTableController tableControllerForTableViewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.predicate = predicate;
tableController.sortDescriptors = sortDescriptors;
tableController.sectionNameKeyPath = @"name";
tableController.cacheName = @"allHumansCache";
[tableController loadTable];
-
+
assertThat(tableController.viewController, is(equalTo(viewController)));
- assertThat(tableController.tableView, is(equalTo(tableView)));
assertThat(tableController.resourcePath, is(equalTo(@"/JSON/humans/all.json")));
assertThat(tableController.fetchRequest, is(notNilValue()));
assertThat([tableController.fetchRequest predicate], is(equalTo(predicate)));
@@ -254,10 +238,10 @@ - (void)testAlwaysHaveAtLeastOneSection {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController loadTable];
-
+
assertThatInt(tableController.sectionCount, is(equalToInt(1)));
}
@@ -269,7 +253,7 @@ - (void)testProperlyCountSections {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.sectionNameKeyPath = @"name";
[tableController loadTable];
@@ -282,7 +266,7 @@ - (void)testProperlyCountRows {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController loadTable];
assertThatInt([tableController rowCount], is(equalToInt(2)));
@@ -294,7 +278,7 @@ - (void)testProperlyCountRowsWithHeaderItems {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -312,7 +296,7 @@ - (void)testProperlyCountRowsWithEmptyItemWhenEmpty {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController setEmptyItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Empty";
@@ -330,7 +314,7 @@ - (void)testProperlyCountRowsWithEmptyItemWhenFull {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController setEmptyItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Empty";
@@ -348,7 +332,7 @@ - (void)testProperlyCountRowsWithHeaderAndEmptyItemsWhenEmptyDontShowHeaders {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -369,11 +353,8 @@ - (void)testProperlyCountRowsWithHeaderAndEmptyItemsWhenEmptyDontShowHeaders {
- (void)testProperlyCountRowsWithHeaderAndEmptyItemsWhenEmptyShowHeaders {
[self bootstrapEmptyStoreAndCache];
- UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
- RKFetchedResultsTableController* tableController =
- [[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ RKFetchedResultsTableController* tableController = [RKFetchedResultsTableController tableControllerForTableViewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -394,11 +375,8 @@ - (void)testProperlyCountRowsWithHeaderAndEmptyItemsWhenEmptyShowHeaders {
- (void)testProperlyCountRowsWithHeaderAndEmptyItemsWhenFull {
[self bootstrapStoreAndCache];
- UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
- RKFetchedResultsTableController* tableController =
- [[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ RKFetchedResultsTableController* tableController = [RKFetchedResultsTableController tableControllerForTableViewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -440,11 +418,11 @@ - (void)testReturnTheNumberOfSectionsInTableView {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.sectionNameKeyPath = @"name";
[tableController loadTable];
-
+
assertThatInt([tableController numberOfSectionsInTableView:tableView], is(equalToInt(2)));
}
@@ -454,10 +432,10 @@ - (void)testReturnTheNumberOfRowsInSectionInTableView {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController loadTable];
-
+
assertThatInt([tableController tableView:tableView numberOfRowsInSection:0], is(equalToInt(2)));
}
@@ -467,11 +445,11 @@ - (void)testReturnTheHeaderTitleForSection {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.sectionNameKeyPath = @"name";
[tableController loadTable];
-
+
assertThat([tableController tableView:tableView titleForHeaderInSection:1], is(equalTo(@"other")));
}
@@ -481,16 +459,16 @@ - (void)testReturnTheTableViewCellForRowAtIndexPath {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController loadTable];
-
+
RKTableViewCellMapping* cellMapping = [RKTableViewCellMapping mappingForClass:[UITableViewCell class]];
[cellMapping mapKeyPath:@"name" toAttribute:@"textLabel.text"];
RKTableViewCellMappings* mappings = [RKTableViewCellMappings new];
[mappings setCellMapping:cellMapping forClass:[RKHuman class]];
tableController.cellMappings = mappings;
-
+
UITableViewCell* cell = [tableController tableView:tableController.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
assertThat(cell.textLabel.text, is(equalTo(@"blake")));
}
@@ -503,13 +481,14 @@ - (void)testReturnTheObjectForARowAtIndexPath {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController loadTable];
-
+
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
RKHuman* blake = [RKHuman findFirstByAttribute:@"name" withValue:@"blake"];
assertThatBool(blake == [tableController objectForRowAtIndexPath:indexPath], is(equalToBool(YES)));
+ [tableController release];
}
#pragma mark - Editing
@@ -520,33 +499,33 @@ - (void)testFireADeleteRequestWhenTheCanEditRowsPropertyIsSet {
[[RKObjectManager sharedManager].router routeClass:[RKHuman class]
toResourcePath:@"/humans/:railsID"
forMethod:RKRequestMethodDELETE];
- UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
- RKFetchedResultsTableController* tableController =
- [[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ RKFetchedResultsTableController* tableController = [RKFetchedResultsTableController tableControllerForTableViewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.canEditRows = YES;
+ RKTableViewCellMapping *cellMapping = [RKTableViewCellMapping cellMapping];
+ [cellMapping mapKeyPath:@"name" toAttribute:@"textLabel.text"];
+ [tableController mapObjectsWithClass:[RKHuman class] toTableCellsWithMapping:cellMapping];
[tableController loadTable];
-
+
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
NSIndexPath* deleteIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
RKHuman* blake = [RKHuman findFirstByAttribute:@"name" withValue:@"blake"];
RKHuman* other = [RKHuman findFirstByAttribute:@"name" withValue:@"other"];
-
+
assertThatInt([tableController rowCount], is(equalToInt(2)));
assertThat([tableController objectForRowAtIndexPath:indexPath], is(equalTo(other)));
assertThat([tableController objectForRowAtIndexPath:deleteIndexPath], is(equalTo(blake)));
BOOL delegateCanEdit = [tableController tableView:tableController.tableView
- canEditRowAtIndexPath:deleteIndexPath];
+ canEditRowAtIndexPath:deleteIndexPath];
assertThatBool(delegateCanEdit, is(equalToBool(YES)));
-
+
[RKTestNotificationObserver waitForNotificationWithName:RKRequestDidLoadResponseNotification usingBlock:^{
[tableController tableView:tableController.tableView
- commitEditingStyle:UITableViewCellEditingStyleDelete
- forRowAtIndexPath:deleteIndexPath];
+ commitEditingStyle:UITableViewCellEditingStyleDelete
+ forRowAtIndexPath:deleteIndexPath];
}];
-
+
assertThatInt([tableController rowCount], is(equalToInt(1)));
assertThat([tableController objectForRowAtIndexPath:deleteIndexPath], is(equalTo(other)));
assertThatBool([blake isDeleted], is(equalToBool(YES)));
@@ -555,63 +534,63 @@ - (void)testFireADeleteRequestWhenTheCanEditRowsPropertyIsSet {
- (void)testLocallyCommitADeleteWhenTheCanEditRowsPropertyIsSet {
[self bootstrapStoreAndCache];
[self stubObjectManagerToOnline];
-
+
UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.canEditRows = YES;
[tableController loadTable];
-
+
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSIndexPath* deleteIndexPath = [NSIndexPath indexPathForRow:1 inSection:0];
RKHuman* blake = [RKHuman findFirstByAttribute:@"name" withValue:@"blake"];
RKHuman* other = [RKHuman findFirstByAttribute:@"name" withValue:@"other"];
blake.railsID = nil;
other.railsID = nil;
-
+
NSError* error = nil;
[blake.managedObjectContext save:&error];
assertThat(error, is(nilValue()));
-
+
assertThatInt([tableController rowCount], is(equalToInt(2)));
assertThat([tableController objectForRowAtIndexPath:indexPath], is(equalTo(blake)));
assertThat([tableController objectForRowAtIndexPath:deleteIndexPath], is(equalTo(other)));
BOOL delegateCanEdit = [tableController tableView:tableController.tableView
- canEditRowAtIndexPath:deleteIndexPath];
+ canEditRowAtIndexPath:deleteIndexPath];
assertThatBool(delegateCanEdit, is(equalToBool(YES)));
[tableController tableView:tableController.tableView
- commitEditingStyle:UITableViewCellEditingStyleDelete
- forRowAtIndexPath:deleteIndexPath];
+ commitEditingStyle:UITableViewCellEditingStyleDelete
+ forRowAtIndexPath:deleteIndexPath];
assertThatInt([tableController rowCount], is(equalToInt(1)));
assertThat([tableController objectForRowAtIndexPath:indexPath], is(equalTo(blake)));
}
- (void)testNotCommitADeletionWhenTheCanEditRowsPropertyIsNotSet {
[self bootstrapStoreAndCache];
[self stubObjectManagerToOnline];
-
+
UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController loadTable];
-
+
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
RKHuman* blake = [RKHuman findFirstByAttribute:@"name" withValue:@"blake"];
RKHuman* other = [RKHuman findFirstByAttribute:@"name" withValue:@"other"];
-
+
assertThatInt([tableController rowCount], is(equalToInt(2)));
BOOL delegateCanEdit = [tableController tableView:tableController.tableView
- canEditRowAtIndexPath:indexPath];
+ canEditRowAtIndexPath:indexPath];
assertThatBool(delegateCanEdit, is(equalToBool(NO)));
[tableController tableView:tableController.tableView
- commitEditingStyle:UITableViewCellEditingStyleDelete
- forRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
+ commitEditingStyle:UITableViewCellEditingStyleDelete
+ forRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
assertThatInt([tableController rowCount], is(equalToInt(2)));
assertThat([tableController objectForRowAtIndexPath:indexPath], is(equalTo(blake)));
assertThat([tableController objectForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]],
@@ -621,27 +600,27 @@ - (void)testNotCommitADeletionWhenTheCanEditRowsPropertyIsNotSet {
- (void)testDoNothingToCommitAnInsertionWhenTheCanEditRowsPropertyIsSet {
[self bootstrapStoreAndCache];
[self stubObjectManagerToOnline];
-
+
UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.canEditRows = YES;
[tableController loadTable];
-
+
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
RKHuman* blake = [RKHuman findFirstByAttribute:@"name" withValue:@"blake"];
RKHuman* other = [RKHuman findFirstByAttribute:@"name" withValue:@"other"];
-
+
assertThatInt([tableController rowCount], is(equalToInt(2)));
BOOL delegateCanEdit = [tableController tableView:tableController.tableView
- canEditRowAtIndexPath:indexPath];
+ canEditRowAtIndexPath:indexPath];
assertThatBool(delegateCanEdit, is(equalToBool(YES)));
[tableController tableView:tableController.tableView
- commitEditingStyle:UITableViewCellEditingStyleInsert
- forRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
+ commitEditingStyle:UITableViewCellEditingStyleInsert
+ forRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
assertThatInt([tableController rowCount], is(equalToInt(2)));
assertThat([tableController objectForRowAtIndexPath:indexPath], is(equalTo(blake)));
assertThat([tableController objectForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]],
@@ -654,22 +633,22 @@ - (void)testNotMoveARowWhenTheCanMoveRowsPropertyIsSet {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.canMoveRows = YES;
[tableController loadTable];
-
+
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
RKHuman* blake = [RKHuman findFirstByAttribute:@"name" withValue:@"blake"];
RKHuman* other = [RKHuman findFirstByAttribute:@"name" withValue:@"other"];
-
+
assertThatInt([tableController rowCount], is(equalToInt(2)));
BOOL delegateCanMove = [tableController tableView:tableController.tableView
- canMoveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
+ canMoveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
assertThatBool(delegateCanMove, is(equalToBool(YES)));
[tableController tableView:tableController.tableView
- moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
- toIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
+ moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
+ toIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
assertThatInt([tableController rowCount], is(equalToInt(2)));
assertThat([tableController objectForRowAtIndexPath:indexPath], is(equalTo(blake)));
assertThat([tableController objectForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]],
@@ -684,7 +663,7 @@ - (void)testDetermineIfASectionIndexIsAHeaderSection {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController loadTable];
assertThatBool([tableController isHeaderSection:0], is(equalToBool(YES)));
@@ -698,7 +677,7 @@ - (void)testDetermineIfARowIndexIsAHeaderRow {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -718,7 +697,7 @@ - (void)testDetermineIfASectionIndexIsAFooterSectionSingleSection {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addFooterRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Footer";
@@ -738,7 +717,7 @@ - (void)testDetermineIfASectionIndexIsAFooterSectionMultipleSections {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.sectionNameKeyPath = @"name";
[tableController addFooterRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
@@ -759,7 +738,7 @@ - (void)testDetermineIfARowIndexIsAFooterRow {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addFooterRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Footer";
@@ -779,7 +758,7 @@ - (void)testDetermineIfASectionIndexIsAnEmptySection {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController loadTable];
assertThatBool([tableController isEmptySection:0], is(equalToBool(YES)));
@@ -793,7 +772,7 @@ - (void)testDetermineIfARowIndexIsAnEmptyRow {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController loadTable];
assertThatBool([tableController isEmptyRow:0], is(equalToBool(YES)));
@@ -807,7 +786,7 @@ - (void)testDetermineIfAnIndexPathIsAHeaderIndexPath {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -830,7 +809,7 @@ - (void)testDetermineIfAnIndexPathIsAFooterIndexPath {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addFooterRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Footer";
@@ -853,7 +832,7 @@ - (void)testDetermineIfAnIndexPathIsAnEmptyIndexPathSingleSectionEmptyItemOnly {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController setEmptyItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Empty";
@@ -876,7 +855,7 @@ - (void)testConvertAnIndexPathForHeaderRows {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -897,7 +876,7 @@ - (void)testConvertAnIndexPathForFooterRowsSingleSection {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addFooterRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Footer";
@@ -917,7 +896,7 @@ - (void)testConvertAnIndexPathForFooterRowsMultipleSections {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.sectionNameKeyPath = @"name";
[tableController addFooterRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
@@ -939,7 +918,7 @@ - (void)testConvertAnIndexPathForEmptyRow {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController setEmptyItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Empty";
@@ -960,7 +939,7 @@ - (void)testConvertAnIndexPathForHeaderFooterRowsSingleSection {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -987,7 +966,7 @@ - (void)testConvertAnIndexPathForHeaderFooterRowsMultipleSections {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.sectionNameKeyPath = @"name";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
@@ -1016,7 +995,7 @@ - (void)testConvertAnIndexPathForHeaderFooterEmptyRowsSingleSection {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -1050,7 +1029,7 @@ - (void)testConvertAnIndexPathForHeaderFooterEmptyRowsMultipleSections {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.sectionNameKeyPath = @"name";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
@@ -1084,7 +1063,7 @@ - (void)testConvertAnIndexPathForHeaderEmptyRows {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -1110,7 +1089,7 @@ - (void)testShowHeaderRows {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
RKTableItem* headerRow = [RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -1122,10 +1101,10 @@ - (void)testShowHeaderRows {
tableController.showsHeaderRowsWhenEmpty = NO;
tableController.showsFooterRowsWhenEmpty = NO;
[tableController loadTable];
-
+
RKHuman* blake = [RKHuman findFirstByAttribute:@"name" withValue:@"blake"];
RKHuman* other = [RKHuman findFirstByAttribute:@"name" withValue:@"other"];
-
+
assertThatInt([tableController rowCount], is(equalToInt(3)));
assertThat([tableController objectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]], is(equalTo(headerRow)));
assertThat([tableController objectForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]], is(equalTo(blake)));
@@ -1139,7 +1118,7 @@ - (void)testShowFooterRows {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
RKTableItem* footerRow = [RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Footer";
@@ -1151,10 +1130,10 @@ - (void)testShowFooterRows {
tableController.showsHeaderRowsWhenEmpty = NO;
tableController.showsFooterRowsWhenEmpty = NO;
[tableController loadTable];
-
+
RKHuman* blake = [RKHuman findFirstByAttribute:@"name" withValue:@"blake"];
RKHuman* other = [RKHuman findFirstByAttribute:@"name" withValue:@"other"];
-
+
assertThatInt([tableController rowCount], is(equalToInt(3)));
assertThat([tableController objectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]], is(equalTo(blake)));
assertThat([tableController objectForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]], is(equalTo(other)));
@@ -1168,7 +1147,7 @@ - (void)testHideHeaderRowsWhenEmptyWhenPropertyIsNotSet {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -1179,7 +1158,7 @@ - (void)testHideHeaderRowsWhenEmptyWhenPropertyIsNotSet {
tableController.showsHeaderRowsWhenEmpty = NO;
tableController.showsFooterRowsWhenEmpty = NO;
[tableController loadTable];
-
+
assertThatBool(tableController.isLoaded, is(equalToBool(YES)));
assertThatInt([tableController rowCount], is(equalToInt(0)));
assertThatBool(tableController.isEmpty, is(equalToBool(YES)));
@@ -1191,7 +1170,7 @@ - (void)testHideFooterRowsWhenEmptyWhenPropertyIsNotSet {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addFooterRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Footer";
@@ -1202,7 +1181,7 @@ - (void)testHideFooterRowsWhenEmptyWhenPropertyIsNotSet {
tableController.showsHeaderRowsWhenEmpty = NO;
tableController.showsFooterRowsWhenEmpty = NO;
[tableController loadTable];
-
+
assertThatBool(tableController.isLoaded, is(equalToBool(YES)));
assertThatInt([tableController rowCount], is(equalToInt(0)));
assertThatBool(tableController.isEmpty, is(equalToBool(YES)));
@@ -1214,7 +1193,7 @@ - (void)testRemoveHeaderAndFooterCountsWhenDeterminingIsEmpty {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -1237,7 +1216,7 @@ - (void)testRemoveHeaderAndFooterCountsWhenDeterminingIsEmpty {
tableController.showsHeaderRowsWhenEmpty = NO;
tableController.showsFooterRowsWhenEmpty = NO;
[tableController loadTable];
-
+
assertThatBool(tableController.isLoaded, is(equalToBool(YES)));
assertThatInt([tableController rowCount], is(equalToInt(1)));
assertThatBool(tableController.isEmpty, is(equalToBool(YES)));
@@ -1249,25 +1228,25 @@ - (void)testNotShowTheEmptyItemWhenTheTableIsNotEmpty {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
-
+
RKTableItem* headerRow = [RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
tableItem.cellMapping = [RKTableViewCellMapping cellMappingUsingBlock:^(RKTableViewCellMapping* cellMapping) {
[cellMapping addDefaultMappings];
}];
}];
[tableController addHeaderRowForItem:headerRow];
-
+
RKTableItem* footerRow = [RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Footer";
tableItem.cellMapping = [RKTableViewCellMapping cellMappingUsingBlock:^(RKTableViewCellMapping* cellMapping) {
[cellMapping addDefaultMappings];
}];
}];
[tableController addFooterRowForItem:footerRow];
-
+
RKTableItem* emptyItem = [RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Empty";
tableItem.cellMapping = [RKTableViewCellMapping cellMappingUsingBlock:^(RKTableViewCellMapping* cellMapping) {
@@ -1278,10 +1257,10 @@ - (void)testNotShowTheEmptyItemWhenTheTableIsNotEmpty {
tableController.showsHeaderRowsWhenEmpty = NO;
tableController.showsFooterRowsWhenEmpty = NO;
[tableController loadTable];
-
+
RKHuman* blake = [RKHuman findFirstByAttribute:@"name" withValue:@"blake"];
RKHuman* other = [RKHuman findFirstByAttribute:@"name" withValue:@"other"];
-
+
assertThatInt([tableController rowCount], is(equalToInt(4)));
assertThat([tableController objectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]], is(equalTo(headerRow)));
assertThat([tableController objectForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]], is(equalTo(blake)));
@@ -1296,7 +1275,7 @@ - (void)testShowTheEmptyItemWhenTheTableIsEmpty {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -1319,7 +1298,7 @@ - (void)testShowTheEmptyItemWhenTheTableIsEmpty {
tableController.showsHeaderRowsWhenEmpty = NO;
tableController.showsFooterRowsWhenEmpty = NO;
[tableController loadTable];
-
+
assertThatBool(tableController.isLoaded, is(equalToBool(YES)));
assertThatInt([tableController rowCount], is(equalToInt(1)));
assertThatBool(tableController.isEmpty, is(equalToBool(YES)));
@@ -1331,7 +1310,7 @@ - (void)testShowTheEmptyItemPlusHeadersAndFootersWhenTheTableIsEmpty {
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
+ viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
[tableController addHeaderRowForItem:[RKTableItem tableItemUsingBlock:^(RKTableItem* tableItem) {
tableItem.text = @"Header";
@@ -1354,7 +1333,7 @@ - (void)testShowTheEmptyItemPlusHeadersAndFootersWhenTheTableIsEmpty {
tableController.showsHeaderRowsWhenEmpty = YES;
tableController.showsFooterRowsWhenEmpty = YES;
[tableController loadTable];
-
+
assertThatBool(tableController.isLoaded, is(equalToBool(YES)));
assertThatInt([tableController rowCount], is(equalToInt(3)));
assertThatBool(tableController.isEmpty, is(equalToBool(YES)));
@@ -1363,20 +1342,20 @@ - (void)testShowTheEmptyItemPlusHeadersAndFootersWhenTheTableIsEmpty {
- (void)testShowTheEmptyImageAfterLoadingAnEmptyCollectionIntoAnEmptyFetch {
[self bootstrapEmptyStoreAndCache];
[self stubObjectManagerToOnline];
-
+
UITableView* tableView = [UITableView new];
-
+
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController = [[RKFetchedResultsTableController alloc] initWithTableView:tableView
- viewController:viewController];
-
+ viewController:viewController];
+
UIImage *image = [RKTestFixture imageWithContentsOfFixture:@"blake.png"];
-
+
tableController.imageForEmpty = image;
tableController.resourcePath = @"/empty/array";
tableController.autoRefreshFromNetwork = YES;
[tableController.cache invalidateAll];
-
+
[RKTestNotificationObserver waitForNotificationWithName:RKTableControllerDidFinishLoadNotification usingBlock:^{
[tableController loadTable];
}];
@@ -1403,4 +1382,86 @@ - (void)testPostANotificationWhenObjectsAreLoaded {
[observerMock verify];
}
+#pragma mark - Delegate Methods
+
+- (void)testDelegateIsInformedOnInsertSection {
+ [self bootstrapStoreAndCache];
+ RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
+ RKFetchedResultsTableController* tableController =
+ [[RKFetchedResultsTableController alloc] initWithTableView:viewController.tableView viewController:viewController];
+ RKTableViewCellMapping *cellMapping = [RKTableViewCellMapping cellMapping];
+ [cellMapping mapKeyPath:@"name" toAttribute:@"textLabel.text"];
+ [tableController mapObjectsWithClass:[RKHuman class] toTableCellsWithMapping:cellMapping];
+ tableController.resourcePath = @"/JSON/humans/all.json";
+ tableController.cacheName = @"allHumansCache";
+
+ RKFetchedResultsTableControllerTestDelegate *delegate = [RKFetchedResultsTableControllerTestDelegate tableControllerDelegate];
+ id mockDelegate = [OCMockObject partialMockForObject:delegate];
+ [[mockDelegate expect] tableController:tableController didInsertSectionAtIndex:0];
+ tableController.delegate = mockDelegate;
+ [[[[UIApplication sharedApplication] windows] objectAtIndex:0] setRootViewController:viewController];
+ [tableController loadTable];
+ assertThatInt([tableController rowCount], is(equalToInt(2)));
+ assertThatInt([tableController sectionCount], is(equalToInt(1)));
+ [mockDelegate verify];
+}
+
+- (void)testDelegateIsInformedOfDidStartLoad {
+ [self bootstrapStoreAndCache];
+ RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
+ RKFetchedResultsTableController* tableController =
+ [[RKFetchedResultsTableController alloc] initWithTableView:viewController.tableView viewController:viewController];
+ RKTableViewCellMapping *cellMapping = [RKTableViewCellMapping cellMapping];
+ [cellMapping mapKeyPath:@"name" toAttribute:@"textLabel.text"];
+ [tableController mapObjectsWithClass:[RKHuman class] toTableCellsWithMapping:cellMapping];
+ tableController.resourcePath = @"/JSON/humans/all.json";
+ tableController.cacheName = @"allHumansCache";
+
+ id mockDelegate = [OCMockObject niceMockForProtocol:@protocol(RKFetchedResultsTableControllerDelegate)];
+ [[mockDelegate expect] tableControllerDidStartLoad:tableController];
+ tableController.delegate = mockDelegate;
+ [[[[UIApplication sharedApplication] windows] objectAtIndex:0] setRootViewController:viewController];
+ [tableController loadTable];
+ [mockDelegate verify];
+}
+
+- (void)testDelegateIsInformedOfDidFinishLoad {
+ [self bootstrapStoreAndCache];
+ RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
+ RKFetchedResultsTableController* tableController =
+ [[RKFetchedResultsTableController alloc] initWithTableView:viewController.tableView viewController:viewController];
+ RKTableViewCellMapping *cellMapping = [RKTableViewCellMapping cellMapping];
+ [cellMapping mapKeyPath:@"name" toAttribute:@"textLabel.text"];
+ [tableController mapObjectsWithClass:[RKHuman class] toTableCellsWithMapping:cellMapping];
+ tableController.resourcePath = @"/JSON/humans/all.json";
+ tableController.cacheName = @"allHumansCache";
+
+ id mockDelegate = [OCMockObject niceMockForProtocol:@protocol(RKFetchedResultsTableControllerDelegate)];
+ [[mockDelegate expect] tableControllerDidFinishLoad:tableController];
+ tableController.delegate = mockDelegate;
+ [[[[UIApplication sharedApplication] windows] objectAtIndex:0] setRootViewController:viewController];
+ [tableController loadTable];
+ [mockDelegate verify];
+}
+
+- (void)testDelegateIsInformedOfDidInsertObjectAtIndexPath {
+ [self bootstrapStoreAndCache];
+ RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
+ RKFetchedResultsTableController* tableController =
+ [[RKFetchedResultsTableController alloc] initWithTableView:viewController.tableView viewController:viewController];
+ RKTableViewCellMapping *cellMapping = [RKTableViewCellMapping cellMapping];
+ [cellMapping mapKeyPath:@"name" toAttribute:@"textLabel.text"];
+ [tableController mapObjectsWithClass:[RKHuman class] toTableCellsWithMapping:cellMapping];
+ tableController.resourcePath = @"/JSON/humans/all.json";
+ tableController.cacheName = @"allHumansCache";
+
+ id mockDelegate = [OCMockObject niceMockForProtocol:@protocol(RKFetchedResultsTableControllerDelegate)];
+ [[mockDelegate expect] tableController:tableController didInsertObject:OCMOCK_ANY atIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
+ [[mockDelegate expect] tableController:tableController didInsertObject:OCMOCK_ANY atIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
+ tableController.delegate = mockDelegate;
+ [[[[UIApplication sharedApplication] windows] objectAtIndex:0] setRootViewController:viewController];
+ [tableController loadTable];
+ [mockDelegate verify];
+}
+
@end
View
337 Tests/Application/UI/RKTableControllerTest.m
@@ -12,103 +12,23 @@
#import "RKTestUser.h"
#import "RKMappableObject.h"
#import "RKAbstractTableController_Internals.h"
+#import "RKTableControllerTestDelegate.h"
// Expose the object loader delegate for testing purposes...
@interface RKTableController () <RKObjectLoaderDelegate>
- (void)animationDidStopAddingSwipeView:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context;
@end
-@interface RKTestTableControllerDelegate : NSObject <RKTableControllerDelegate>
-
-@property(nonatomic, readonly, getter = isCancelled) BOOL cancelled;
-@property(nonatomic, assign) NSTimeInterval timeout;
-@property(nonatomic, assign) BOOL awaitingResponse;
-
-+ (id)tableControllerDelegate;
-- (void)waitForLoad;
-@end
-
-@implementation RKTestTableControllerDelegate
-
-@synthesize timeout = _timeout;
-@synthesize awaitingResponse = _awaitingResponse;
-@synthesize cancelled = _cancelled;
-
-+ (id)tableControllerDelegate {
- return [[self new] autorelease];
-}
-
-- (id)init {
- self = [super init];
- if (self) {
- _timeout = 3;
- _awaitingResponse = NO;
- _cancelled = NO;
- }
-
- return self;
-}
-
-- (void)waitForLoad {
- _awaitingResponse = YES;
- NSDate* startDate = [NSDate date];
-
- while (_awaitingResponse) {
- NSLog(@"Awaiting response = %d", _awaitingResponse);
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
- if ([[NSDate date] timeIntervalSinceDate:startDate] > self.timeout) {
- NSLog(@"%@: Timed out!!!", self);
- _awaitingResponse = NO;
- [NSException raise:nil format:@"*** Operation timed out after %f seconds...", self.timeout];
- }
- }
-}
-
-#pragma RKTableControllerDelegate methods
-
-- (void)tableControllerDidFinishLoad:(RKAbstractTableController*)tableController {
- _awaitingResponse = NO;
-}
-
-- (void)tableController:(RKAbstractTableController*)tableController didFailLoadWithError:(NSError *)error {
- _awaitingResponse = NO;
-}
-
-- (void)tableControllerDidCancelLoad:(RKAbstractTableController*)tableController {
- _awaitingResponse = NO;
- _cancelled = YES;
-}
-
-// NOTE - Delegate methods below are implemented to allow trampoline through
-// OCMock expectations
-
-- (void)tableControllerDidStartLoad:(RKAbstractTableController*)tableController {}
-- (void)tableControllerDidBecomeEmpty:(RKAbstractTableController*)tableController {}
-- (void)tableController:(RKAbstractTableController*)tableController willLoadTableWithObjectLoader:(RKObjectLoader*)objectLoader {}
-- (void)tableController:(RKAbstractTableController*)tableController didLoadTableWithObjectLoader:(RKObjectLoader*)objectLoader {}
-- (void)tableController:(RKAbstractTableController*)tableController willBeginEditing:(id)object atIndexPath:(NSIndexPath*)indexPath {}
-- (void)tableController:(RKAbstractTableController*)tableController didEndEditing:(id)object atIndexPath:(NSIndexPath*)indexPath {}
-- (void)tableController:(RKAbstractTableController*)tableController didInsertSection:(RKTableSection*)section atIndex:(NSUInteger)sectionIndex {}
-- (void)tableController:(RKAbstractTableController*)tableController didRemoveSection:(RKTableSection*)section atIndex:(NSUInteger)sectionIndex {}
-- (void)tableController:(RKAbstractTableController*)tableController didInsertObject:(id)object atIndexPath:(NSIndexPath*)indexPath {}
-- (void)tableController:(RKAbstractTableController*)tableController didUpdateObject:(id)object atIndexPath:(NSIndexPath*)indexPath {}
-- (void)tableController:(RKAbstractTableController*)tableController didDeleteObject:(id)object atIndexPath:(NSIndexPath*)indexPath {}
-- (void)tableController:(RKAbstractTableController*)tableController willAddSwipeView:(UIView*)swipeView toCell:(UITableViewCell*)cell forObject:(id)object {}
-- (void)tableController:(RKAbstractTableController*)tableController willRemoveSwipeView:(UIView*)swipeView fromCell:(UITableViewCell*)cell forObject:(id)object {}
-- (void)tableControllerDidFinalizeLoad:(RKAbstractTableController *)tableController {}
-
-@end
-
@interface RKTableControllerTestTableViewController : UITableViewController
@end
@implementation RKTableControllerTestTableViewController
@end
-@interface RKTableControllerSpecViewController : UIViewController
+@interface RKTableControllerTestViewController : UIViewController
@end
-@implementation RKTableControllerSpecViewController
+@implementation RKTableControllerTestViewController
@end
@interface RKTestUserTableViewCell : UITableViewCell
@@ -145,7 +65,7 @@ - (void)testInitializeWithATableViewController {
- (void)testInitializeWithATableViewAndViewController {
UITableView* tableView = [UITableView new];
- RKTableControllerSpecViewController* viewController = [RKTableControllerSpecViewController new];
+ RKTableControllerTestViewController* viewController = [RKTableControllerTestViewController new];
RKTableController* tableController = [RKTableController tableControllerWithTableView:tableView forViewController:viewController];
assertThat(tableController.viewController, is(equalTo(viewController)));
assertThat(tableController.tableView, is(equalTo(tableView)));
@@ -192,153 +112,84 @@ - (void)testAddASection {
RKTableControllerTestTableViewController* viewController = [RKTableControllerTestTableViewController new];
RKTableController* tableController = [RKTableController tableControllerForTableViewController:viewController];
RKTableSection* section = [RKTableSection section];
- RKTestTableControllerDelegate* delegate = [RKTestTableControllerDelegate new];
- id mockDelegate = [OCMockObject partialMockForObject:delegate];
- [[[mockDelegate expect] andForwardToRealObject] tableController:tableController
- didInsertSection:section
- atIndex:1];
- tableController.delegate = mockDelegate;
[tableController addSection:section];
assertThatInt([tableController.sections count], is(equalToInt(2)));
- STAssertNoThrow([mockDelegate verify], nil);
}
- (void)testConnectTheSectionToTheTableModelOnAdd {
RKTableControllerTestTableViewController* viewController = [RKTableControllerTestTableViewController new];
RKTableController* tableController = [RKTableController tableControllerForTableViewController:viewController];
R