mirror of
https://github.com/zhigang1992/MagicalRecord.git
synced 2026-05-07 18:36:58 +08:00
Resolve broken PS and PSC tests on Mac
This commit is contained in:
@@ -14,7 +14,6 @@ static NSManagedObjectModel *defaultManagedObjectModel_ = nil;
|
||||
|
||||
@implementation NSManagedObjectModel (MagicalRecord)
|
||||
|
||||
|
||||
+ (NSManagedObjectModel *)MR_defaultManagedObjectModel
|
||||
{
|
||||
if (defaultManagedObjectModel_ == nil)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
//#import "NSManagedObjectModel+MagicalRecord.h"
|
||||
//#import "NSPersistentStore+MagicalRecord.h"
|
||||
|
||||
static NSPersistentStoreCoordinator *defaultCoordinator = nil;
|
||||
static NSPersistentStoreCoordinator *defaultCoordinator_ = nil;
|
||||
|
||||
@implementation NSPersistentStoreCoordinator (MagicalRecord)
|
||||
|
||||
@@ -19,23 +19,40 @@ static NSPersistentStoreCoordinator *defaultCoordinator = nil;
|
||||
{
|
||||
@synchronized (self)
|
||||
{
|
||||
if (defaultCoordinator == nil)
|
||||
if (defaultCoordinator_ == nil)
|
||||
{
|
||||
defaultCoordinator = [self MR_newPersistentStoreCoordinator];
|
||||
defaultCoordinator_ = [self MR_newPersistentStoreCoordinator];
|
||||
}
|
||||
}
|
||||
return defaultCoordinator;
|
||||
return defaultCoordinator_;
|
||||
}
|
||||
|
||||
+ (void) MR_setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator
|
||||
{
|
||||
defaultCoordinator = coordinator;
|
||||
defaultCoordinator_ = coordinator;
|
||||
}
|
||||
|
||||
- (void) createPathToStoreFileIfNeccessary:(NSURL *)urlForStore
|
||||
{
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSURL *pathToStore = [urlForStore URLByDeletingLastPathComponent];
|
||||
|
||||
NSError *error = nil;
|
||||
BOOL pathWasCreated = [fileManager createDirectoryAtURL:pathToStore withIntermediateDirectories:YES attributes:nil error:&error];
|
||||
|
||||
if (!pathWasCreated)
|
||||
{
|
||||
[MagicalRecordHelpers handleErrors:error];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) MR_setupSqliteStoreNamed:(id)storeFileName withOptions:(NSDictionary *)options
|
||||
{
|
||||
NSURL *url = [storeFileName isKindOfClass:[NSURL class]] ? storeFileName : [NSPersistentStore urlForStoreName:storeFileName];
|
||||
NSURL *url = [storeFileName isKindOfClass:[NSURL class]] ? storeFileName : [NSPersistentStore MR_urlForStoreName:storeFileName];
|
||||
NSError *error = nil;
|
||||
|
||||
[self createPathToStoreFileIfNeccessary:url];
|
||||
|
||||
NSPersistentStore *store = [self addPersistentStoreWithType:NSSQLiteStoreType
|
||||
configuration:nil
|
||||
URL:url
|
||||
@@ -45,7 +62,7 @@ static NSPersistentStoreCoordinator *defaultCoordinator = nil;
|
||||
{
|
||||
[MagicalRecordHelpers handleErrors:error];
|
||||
}
|
||||
[NSPersistentStore setDefaultPersistentStore:store];
|
||||
[NSPersistentStore MR_setDefaultPersistentStore:store];
|
||||
}
|
||||
|
||||
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore;
|
||||
@@ -103,7 +120,7 @@ static NSPersistentStoreCoordinator *defaultCoordinator = nil;
|
||||
NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
|
||||
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
|
||||
|
||||
[NSPersistentStore setDefaultPersistentStore:[psc MR_addInMemoryStore]];
|
||||
[NSPersistentStore MR_setDefaultPersistentStore:[psc MR_addInMemoryStore]];
|
||||
return psc;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
{
|
||||
assertThat(error, is(notNilValue()));
|
||||
assertThat([error domain], is(equalTo(@"MRTests")));
|
||||
assertThatInt([error code], is(equalToInteger(1000)));
|
||||
assertThatInteger([error code], is(equalToInteger(1000)));
|
||||
errorHandlerWasCalled_ = YES;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,22 @@
|
||||
|
||||
- (void) testCanFindAURLInTheApplicationSupportLibraryForMacForASpecifiedStoreName
|
||||
{
|
||||
GHFail(@"Test Not Implemented");
|
||||
NSString *storeFileName = @"NotTheDefaultStoreName.storefile";
|
||||
NSString *applicationSupportDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
|
||||
NSString *applicationName = [[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString *)kCFBundleNameKey];
|
||||
NSString *testStorePath = [applicationSupportDirectory stringByAppendingPathComponent:storeFileName];
|
||||
|
||||
BOOL fileWasCreated = [[NSFileManager defaultManager] createFileAtPath:testStorePath contents:[storeFileName dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
|
||||
|
||||
assertThatBool(fileWasCreated, is(equalToBool(YES)));
|
||||
|
||||
NSURL *expectedStoreUrl = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@/%@", applicationSupportDirectory, applicationName, storeFileName]];
|
||||
|
||||
NSURL *foundStoreUrl = [NSPersistentStore urlForStoreName:storeFileName];
|
||||
|
||||
assertThat(foundStoreUrl, is(equalTo(expectedStoreUrl)));
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtPath:testStorePath error:nil];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user