Permalink
Browse files

Fix broken tests on iOS4.3 and iOS5

Fix data import on iOS4.3
  • Loading branch information...
1 parent 07538d5 commit a689dfe612f61ae539f02600fc926c5d12b3b3f4 @casademora casademora committed Dec 11, 2011
@@ -1196,11 +1196,12 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "iOS App Unit Tests/iOS App Unit Tests-Prefix.pch";
GCC_PREPROCESSOR_DEFINITIONS = (
+ "MR_SHORTHAND=1",
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
- GCC_VERSION = com.apple.compilers.llvmgcc42;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
@@ -1218,7 +1219,7 @@
);
MOMC_NO_INVERSE_RELATIONSHIP_WARNINGS = YES;
MOMC_NO_WARNINGS = YES;
- OTHER_CFLAGS = "-DMR_SHORTHAND";
+ OTHER_CFLAGS = "-DMR_ENABLE_LOGGING";
OTHER_LDFLAGS = (
"-all_load",
"-ObjC",
@@ -1249,7 +1250,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "iOS App Unit Tests/iOS App Unit Tests-Prefix.pch";
- GCC_VERSION = com.apple.compilers.llvmgcc42;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
@@ -110,7 +110,7 @@ - (void) MR_addObject:(NSManagedObject *)relatedObject forRelationship:(NSRelati
if ([relationshipInfo isToMany])
{
addRelationMessageFormat = @"add%@Object:";
- if ([relationshipInfo isOrdered])
+ if ([relationshipInfo respondsToSelector:@selector(isOrdered)] && [relationshipInfo isOrdered])
{
//Need to get the ordered set
NSString *selectorName = [[relationshipInfo name] stringByAppendingString:@"Set"];
@@ -10,6 +10,7 @@
static NSManagedObjectContext *defaultManageObjectContext_ = nil;
static NSString const * kMagicalRecordManagedObjectContextKey = @"MagicalRecord_NSManagedObjectContextForThreadKey";
+static NSString const * kMagicalRecordNotifiesMainContextAssociatedValueKey = @"kMagicalRecordNotifiesMainContextOnSave";
NSString * const kMagicalRecordDidMergeChangesFromiCloudNotification = @"kMagicalRecordDidMergeChangesFromiCloudNotification";
@interface NSManagedObjectContext (MagicalRecordPrivate)
@@ -220,22 +221,33 @@ - (BOOL) MR_saveOnMainThread;
- (BOOL) MR_notifiesMainContextOnSave;
{
- NSNumber *notifies = objc_getAssociatedObject(self, @"notifiesMainContext");
+ THREAD_ISOLATION_ENABLED(
+ NSNumber *notifies = objc_getAssociatedObject(self, kMagicalRecordNotifiesMainContextAssociatedValueKey);
return notifies ? [notifies boolValue] : NO;
+ )
+ PRIVATE_QUEUES_ENABLED(
+ return [self parentContext] == [[self class] MR_defaultContext];
+ )
+ return NO;
}
- (void) MR_setNotifiesMainContextOnSave:(BOOL)enabled;
{
NSManagedObjectContext *mainContext = [[self class] MR_defaultContext];
if (self != mainContext)
{
+ THREAD_ISOLATION_ENABLED(
SEL selector = enabled ? @selector(MR_observeContextOnMainThread:) : @selector(MR_stopObservingContext:);
- objc_setAssociatedObject(self, @"notifiesMainContext", [NSNumber numberWithBool:enabled], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ objc_setAssociatedObject(self, kMagicalRecordNotifiesMainContextAssociatedValueKey, [NSNumber numberWithBool:enabled], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[mainContext performSelector:selector withObject:self];
#pragma clang diagnostic pop
+ )
+ PRIVATE_QUEUES_ENABLED(
+ [self setParentContext:mainContext];
+ )
}
}
@@ -267,10 +279,12 @@ + (NSManagedObjectContext *) MR_contextWithStoreCoordinator:(NSPersistentStoreCo
{
MRLog(@"Creating MOContext %@", [NSThread isMainThread] ? @" *** On Main Thread ***" : @"");
THREAD_ISOLATION_ENABLED(
- context = [[NSManagedObjectContext alloc] init];
- [context setPersistentStoreCoordinator:coordinator];
+ MRLog(@"Creating context in Thread Isolation Mode");
+ context = [[NSManagedObjectContext alloc] init];
+ [context setPersistentStoreCoordinator:coordinator];
)
PRIVATE_QUEUES_ENABLED(
+ MRLog(@"Creating context in Context Private Queue Mode");
context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[context performBlockAndWait:^{
[context setPersistentStoreCoordinator:coordinator];
@@ -300,12 +314,14 @@ + (NSManagedObjectContext *) MR_contextThatNotifiesDefaultContextOnMainThread;
THREAD_ISOLATION_ENABLED
(
+ MRLog(@"Using Thread Isolation Mode");
context = [self MR_context];
context.MR_notifiesMainContextOnSave = YES;
)
PRIVATE_QUEUES_ENABLED
(
+ MRLog(@"Using Private queue mode");
context = [[self alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[context performBlockAndWait:^{
[context setPersistentStoreCoordinator:[NSPersistentStoreCoordinator MR_defaultStoreCoordinator]];
@@ -23,16 +23,18 @@ + (id) dataFromJSONFixtureNamed:(NSString *)fixtureName
{
NSString *resource = [[NSBundle mainBundle] pathForResource:fixtureName ofType:@"json"];
-#ifdef __IPHONE_5_0
- NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:resource];
- [inputStream open];
-
- return [NSJSONSerialization JSONObjectWithStream:inputStream options:0 error:nil];
-#else
- NSData *jsonData = [NSData dataWithContentsOfFile:resource];
- return [jsonData objectFromJSONData];
-#endif
-
+ if (NSClassFromString(@"NSJSONSerialization"))
+ {
+ NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:resource];
+ [inputStream open];
+
+ return [NSJSONSerialization JSONObjectWithStream:inputStream options:0 error:nil];
+ }
+ else
+ {
+ NSData *jsonData = [NSData dataWithContentsOfFile:resource];
+ return [jsonData objectFromJSONData];
+ }
}
@end
@@ -36,7 +36,7 @@ - (void) setupTestData
- (void) setUp
{
[super setUp];
- self.testEntity = [SingleRelatedEntity MR_importFromDictionary:self.testEntityData];
+ self.singleTestEntity = [SingleRelatedEntity MR_importFromDictionary:self.testEntityData];
[[NSManagedObjectContext MR_defaultContext] MR_save];
}
@@ -17,6 +17,7 @@ - (void) setUp
{
[MagicalRecordHelpers setDefaultModelNamed:@"TestModel.momd"];
[MagicalRecordHelpers setupCoreDataStackWithInMemoryStore];
+ //[MagicalRecordHelpers setupCoreDataStack];
if ([self respondsToSelector:@selector(setupTestData)])
{
@@ -10,6 +10,16 @@
@implementation NSManagedObjectContextHelperTests
+- (void) setUp
+{
+ [MagicalRecordHelpers setupCoreDataStackWithInMemoryStore];
+}
+
+- (void) tearDown
+{
+ [MagicalRecordHelpers cleanUp];
+}
+
- (void) testCanCreateContextForCurrentThead
{
NSManagedObjectContext *firstContext = [NSManagedObjectContext MR_contextForCurrentThread];
@@ -22,7 +32,7 @@ - (void) testCanNotifyDefaultContextOnSave
{
NSManagedObjectContext *testContext = [NSManagedObjectContext MR_contextThatNotifiesDefaultContextOnMainThread];
- assertThatBool(testContext.MR_notifiesMainContextOnSave, is(equalToBool(YES)));
+ assertThatBool([testContext MR_notifiesMainContextOnSave], is(equalToBool(YES)));
}

0 comments on commit a689dfe

Please sign in to comment.