Writing more assertions to verify import is occurring properly

This commit is contained in:
Saul Mora
2011-08-11 17:15:37 -06:00
parent f16a23aa27
commit 864408fae5
6 changed files with 33 additions and 23 deletions

View File

@@ -19,7 +19,9 @@ extern NSString * const kMagicalRecordImportRelationshipTypeKey;
@interface NSManagedObject (NSManagedObject_DataImport)
- (void) MR_setValuesForKeysWithJSONDictionary:(NSDictionary *)jsonData;
+ (id) MR_importFromDictionary:(NSDictionary *)data;
+ (id) MR_importFromDictionary:(NSDictionary *)data inContext:(NSManagedObjectContext *)context;
@end

View File

@@ -215,9 +215,17 @@ NSString * const kMagicalRecordImportRelationshipTypeKey = @"type";
return [self MR_importFromDictionary:data inContext:[NSManagedObjectContext defaultContext]];
}
+ (id) MR_updateFromDictionary:(NSDictionary *)data inContext:(NSManagedObjectContext *)context
{
//find object
//create if not exists
//apply dictionary updates
return nil;
}
+ (id) MR_updateFromDictionary:(NSDictionary *)data
{
return [self MR_importFromDictionary:data inContext:[NSManagedObjectContext defaultContext]];
return [self MR_updateFromDictionary:data inContext:[NSManagedObjectContext defaultContext]];
}
@end

View File

@@ -23,13 +23,13 @@
NSManagedObjectContext *context = [NSManagedObjectContext defaultContext];
MappedEntity *testMappedEntity = [MappedEntity createInContext:context];
testMappedEntity.mappedEntityIDValue = 42;
testMappedEntity.testMappedEntityIDValue = 42;
testMappedEntity.sampleAttribute = @"This attribute created as part of the test case setup";
[context save];
}
- (void) setUpClass
- (void) setUp
{
[NSManagedObjectModel setDefaultManagedObjectModel:[NSManagedObjectModel managedObjectModelNamed:@"TestModel.momd"]];
[MagicalRecordHelpers setupCoreDataStackWithInMemoryStore];
@@ -41,7 +41,7 @@
self.testEntity = [SingleEntityRelatedToMappedEntityUsingDefaults MR_importFromDictionary:singleEntity];
}
- (void) tearDownClass
- (void) tearDown
{
[MagicalRecordHelpers cleanUp];
}
@@ -50,7 +50,10 @@
{
id testRelatedEntity = testEntity.mappedEntity;
assertThat([MappedEntity numberOfEntities], is(equalToInteger(1)));
assertThat(testRelatedEntity, is(notNilValue()));
assertThat([testRelatedEntity sampleAttribute], containsString(@"sample json file"));
}
@end

View File

@@ -30,7 +30,7 @@
[context save];
}
- (void) setUpClass
- (void) setUp
{
[NSManagedObjectModel setDefaultManagedObjectModel:[NSManagedObjectModel managedObjectModelNamed:@"TestModel.momd"]];
[MagicalRecordHelpers setupCoreDataStackWithInMemoryStore];
@@ -42,7 +42,7 @@
self.testEntity = [SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey MR_importFromDictionary:singleEntity];
}
- (void) tearDownClass
- (void) tearDown
{
[MagicalRecordHelpers cleanUp];
}
@@ -56,6 +56,7 @@
NSRelationshipDescription *testRelationship = [[mappedEntity propertiesByName] valueForKey:@"mappedEntity"];
assertThat([[testRelationship userInfo] valueForKey:kMagicalRecordImportRelationshipMapKey], is(equalTo(@"someRandomAttributeName")));
assertThat([MappedEntity numberOfEntities], is(equalToInteger(1)));
assertThat(testRelatedEntity, is(notNilValue()));
assertThat([testRelatedEntity sampleAttribute], is(containsString(@"sample json file")));
}
@@ -69,7 +70,7 @@
NSRelationshipDescription *testRelationship = [[mappedEntity propertiesByName] valueForKey:@"mappedEntity"];
assertThat([[testRelationship userInfo] valueForKey:kMagicalRecordImportRelationshipPrimaryKey], is(equalTo(@"testMappedEntityID")));
assertThat([MappedEntity numberOfEntities], is(equalToInteger(1)));
assertThat([testRelatedEntity testMappedEntityID], is(equalToInteger(42)));
assertThat([testRelatedEntity sampleAttribute], containsString(@"sample json file"));
}

View File

@@ -83,20 +83,19 @@
assertThat(testEntity.mappedStringAttribute, is(equalTo(@"Mapped value")));
}
#if TARGET_OS_IPHONE
#if TARGET_OS_IPHONE && __IPHONE_5_0 >= 50000
- (void) testImportUIColorAttributeToEntity
{
// UIColor *actualColor = testEntity.colorTestAttribute;
//
// CGFloat red, blue, green, alpha;
// [actualColor getRed:&red green:&green blue:&blue alpha:&alpha];
//
//
// assertThatFloat(alpha, is(equalToFloat(1.)));
// assertThatFloat(red, is(equalToFloat(64./255.)));
// assertThatFloat(green, is(equalToFloat(128./255.)));
// assertThatFloat(blue, is(equalToFloat(225./255.)));
UIColor *actualColor = testEntity.colorTestAttribute;
CGFloat red, blue, green, alpha;
[actualColor getRed:&red green:&green blue:&blue alpha:&alpha];
assertThatFloat(alpha, is(equalToFloat(1.)));
assertThatFloat(red, is(equalToFloat(64./255.)));
assertThatFloat(green, is(equalToFloat(128./255.)));
assertThatFloat(blue, is(equalToFloat(225./255.)));
}
#else

View File

@@ -37,11 +37,6 @@
[NSManagedObjectModel setDefaultManagedObjectModel:[NSManagedObjectModel managedObjectModelNamed:@"TestModel.momd"]];
[MagicalRecordHelpers setupCoreDataStackWithInMemoryStore];
// NSURL *storeUrl = [NSPersistentStore MR_urlForStoreName:@"ImportSingleEntityTestStore.sqlite"];
// [[NSFileManager defaultManager] removeItemAtURL:storeUrl error:nil];
//
// [MagicalRecordHelpers setupCoreDataStackWithStoreNamed:@"ImportSingleEntityTestStore.sqlite"];
[self setupTestData];
id singleEntity = [self dataFromJSONFixture];
@@ -62,6 +57,7 @@
assertThat(testRelatedEntity, is(notNilValue()));
assertThat([testRelatedEntity sampleBaseAttribute], containsString(@"BASE"));
assertThatBool([testRelatedEntity respondsToSelector:@selector(sampleConcreteAttribute)], is(equalToBool(NO)));
}
- (void) testImportAnEntityRelatedToAbstractEntityViaToManyRelationship
@@ -73,6 +69,7 @@
assertThat(testRelatedEntity, is(notNilValue()));
assertThat([testRelatedEntity sampleBaseAttribute], containsString(@"BASE"));
assertThatBool([testRelatedEntity respondsToSelector:@selector(sampleConcreteAttribute)], is(equalToBool(NO)));
}