mirror of
https://github.com/zhigang1992/NTDCoreDataTableViewController.git
synced 2026-03-29 15:27:56 +08:00
Code to pass the test.
This commit is contained in:
@@ -36,14 +36,16 @@
|
||||
- (void)performFetch
|
||||
{
|
||||
if (self.fetchedResultsController) {
|
||||
[self.fetchedResultsController performFetch:nil];
|
||||
if (![self.fetchedResultsController performFetch:nil]) {
|
||||
[self logFetchFailure];
|
||||
}
|
||||
}
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
- (void)logFetchFailure
|
||||
{
|
||||
|
||||
NSLog(@"[%@ %@] performFetch: failed", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
|
||||
}
|
||||
|
||||
#pragma mark - View Controller - Life Cycle
|
||||
|
||||
@@ -64,8 +64,9 @@
|
||||
// given
|
||||
sut = [[NTDFakeCDTVC alloc] init];
|
||||
sut.fetchedResultsController = [[NTDFakeFetchedResultsController alloc] init];
|
||||
|
||||
[(NTDFakeFetchedResultsController *)sut.fetchedResultsController setFetchWillSucceed:NO];
|
||||
// when
|
||||
[(NTDFakeCDTVC *)sut setFetchWillFail:NO];
|
||||
[sut performFetch];
|
||||
// then
|
||||
XCTAssertTrue([(NTDFakeCDTVC *)sut loggedFailure]);
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
@interface NTDFakeCDTVC : NTDCoreDataTableViewController
|
||||
|
||||
@property (nonatomic) BOOL fetchWillFail;
|
||||
@property (nonatomic) BOOL loggedFailure;
|
||||
|
||||
@end
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
@interface NTDFakeFetchedResultsController : NSFetchedResultsController
|
||||
|
||||
@property (nonatomic) BOOL fetchWillSucceed;
|
||||
@property (nonatomic) BOOL performFetchIsCalled;
|
||||
|
||||
@end
|
||||
|
||||
@@ -8,12 +8,27 @@
|
||||
|
||||
#import "NTDFakeFetchedResultsController.h"
|
||||
|
||||
@interface NTDFakeFetchedResultsController ()
|
||||
@property (nonatomic) BOOL fakePerformFetchsReturnValue;
|
||||
@end
|
||||
|
||||
@implementation NTDFakeFetchedResultsController
|
||||
|
||||
- (BOOL)performFetch:(NSError *__autoreleasing *)error
|
||||
{
|
||||
self.performFetchIsCalled = YES;
|
||||
return [super performFetch:error];
|
||||
|
||||
if (self.fakePerformFetchsReturnValue) {
|
||||
return self.fetchWillSucceed;
|
||||
} else {
|
||||
return [super performFetch:error];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFetchWillSucceed:(BOOL)fetchWillSucceed
|
||||
{
|
||||
_fetchWillSucceed = fetchWillSucceed;
|
||||
self.fakePerformFetchsReturnValue = YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user