-
Notifications
You must be signed in to change notification settings - Fork 9
/
CoreDataTestCase.m
74 lines (55 loc) · 2.1 KB
/
CoreDataTestCase.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// CoreDataTestCase.m
// ObjectiveRecord
//
// Created by Matthew Newberry on 8/5/10.
// Copyright (c) 2010 Shopify. All rights reserved.
//
#import "CoreDataTestCase.h"
#import "ActiveSupport.h"
#import "ActiveManager.h"
#import "Order.h"
#import "YAJLParsing.h"
@implementation CoreDataTestCase
@synthesize activeManager = _activeManager;
@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
@synthesize testData = _testData;
- (void) setUp{
_activeManager = [ActiveManager shared];
[_activeManager setManagedObjectContext:[self managedObjectContext]];
[_activeManager setParsingClass:[YAJLParsing class]];
}
- (NSManagedObjectContext *) managedObjectContext {
if (_managedObjectContext != nil) {
return _managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator: coordinator];
}
return _managedObjectContext;
}
- (NSManagedObjectModel *)managedObjectModel {
if (_managedObjectModel != nil) {
return _managedObjectModel;
}
_managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:
[NSArray arrayWithObject:[NSBundle bundleForClass:[self class]]]] retain];
return _managedObjectModel;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}
@end