From 6c793549c985ab37e59b953a817f77217126bb99 Mon Sep 17 00:00:00 2001 From: ColinEberhardt Date: Mon, 6 Jan 2014 16:51:51 +0000 Subject: [PATCH 01/10] Very minor typo fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd4abcac..08100faf 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ be invoked if overridden, giving you a convenient hook to upgrade old data. In order to serialize your model objects from or into JSON, you need to implement `` in your `MTLModel` subclass. This allows you to -use `MTLJSONAdapter` convert your model objects from JSON and back: +use `MTLJSONAdapter` to convert your model objects from JSON and back: ```objc NSError *error = nil; From 3b860fd086d79e4a92ef3dd3146c16828c4f32e4 Mon Sep 17 00:00:00 2001 From: Jo Namjun Date: Wed, 8 Jan 2014 15:56:32 +0900 Subject: [PATCH 02/10] Return value for [NSNull null] if key is null in mtl_valueMappingTransformer --- Mantle/NSValueTransformer+MTLPredefinedTransformerAdditions.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mantle/NSValueTransformer+MTLPredefinedTransformerAdditions.m b/Mantle/NSValueTransformer+MTLPredefinedTransformerAdditions.m index 85e84493..632bc03f 100644 --- a/Mantle/NSValueTransformer+MTLPredefinedTransformerAdditions.m +++ b/Mantle/NSValueTransformer+MTLPredefinedTransformerAdditions.m @@ -121,7 +121,7 @@ + (NSValueTransformer *)mtl_valueMappingTransformerWithDictionary:(NSDictionary NSParameterAssert(dictionary.count == [[NSSet setWithArray:dictionary.allValues] count]); return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(id key) { - return dictionary[key]; + return dictionary[key ?: NSNull.null]; } reverseBlock:^(id object) { __block id result = nil; [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id anObject, BOOL *stop) { From df762eefe1bf5dd6c4206f458892f70fd685fc4e Mon Sep 17 00:00:00 2001 From: Tim Gostony Date: Mon, 20 Jan 2014 23:09:18 -0800 Subject: [PATCH 03/10] 2014, yo! --- LICENSE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index 220a9c23..0c46720a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -**Copyright (c) 2012 - 2013, GitHub, Inc.** +**Copyright (c) 2012 - 2014, GitHub, Inc.** **All rights reserved.** Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: From e21c9c327cabcdf2ebef428bdcf2d8fab6c7b70f Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Fri, 24 Jan 2014 13:00:57 +0000 Subject: [PATCH 04/10] MTLManagedObjectAdapter: Fix a bug where errors are silently handled It was using `error` but this error is replaced later in the method and never passed as an error. ```objective-c if (error != NULL) { *error = tmpError; } ``` --- Mantle/MTLManagedObjectAdapter.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mantle/MTLManagedObjectAdapter.m b/Mantle/MTLManagedObjectAdapter.m index c7635e3f..af01edd4 100644 --- a/Mantle/MTLManagedObjectAdapter.m +++ b/Mantle/MTLManagedObjectAdapter.m @@ -392,7 +392,7 @@ - (id)managedObjectFromModel:(MTLModel *)model inse NSValueTransformer *attributeTransformer = [self entityAttributeTransformerForKey:propertyKey]; if (attributeTransformer != nil) transformedValue = [attributeTransformer transformedValue:transformedValue]; - if (![managedObject validateValue:&transformedValue forKey:managedObjectKey error:error]) return NO; + if (![managedObject validateValue:&transformedValue forKey:managedObjectKey error:&tmpError]) return NO; [managedObject setValue:transformedValue forKey:managedObjectKey]; return YES; From 13a39ca0ba509af4a415e85add20375c4181516b Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 27 Jan 2014 12:30:07 +0000 Subject: [PATCH 05/10] MTLManagedObjectAdapter: Add tests for validating values --- MantleTests/MTLManagedObjectAdapterSpec.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MantleTests/MTLManagedObjectAdapterSpec.m b/MantleTests/MTLManagedObjectAdapterSpec.m index 34fb7917..f16305cc 100644 --- a/MantleTests/MTLManagedObjectAdapterSpec.m +++ b/MantleTests/MTLManagedObjectAdapterSpec.m @@ -216,6 +216,16 @@ expect(error).notTo.beNil(); }); + it(@"should return an error if model doesn't validate for attribute description", ^{ + MTLParentTestModel *parentModel = [MTLParentTestModel modelWithDictionary:@{} error:NULL]; + + NSError *error; + NSManagedObject *managedObject = [MTLManagedObjectAdapter managedObjectFromModel:parentModel insertingIntoContext:context error:&error]; + + expect(managedObject).to.beNil(); + expect(error).notTo.beNil(); + }); + it(@"should respect the uniqueness constraint", ^{ NSError *errorOne; MTLParent *parentOne = [MTLManagedObjectAdapter managedObjectFromModel:parentModel insertingIntoContext:context error:&errorOne]; From 027e8c1c4ccb15665f7899729b00c64f0b5212ec Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 27 Jan 2014 12:39:33 +0000 Subject: [PATCH 06/10] MTLManagedObjectAdapter: Fixes an issue with validate for insert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes an issue where validation for insert would return a deleted managed object without an error When it does this in combination with `relationshipModelClassesByPropertyKey` CoreData could raise an exception for using setting child’s in a different context (because it doesn’t have a context) --- Mantle/MTLManagedObjectAdapter.m | 4 ++-- MantleTests/MTLCoreDataTestModels.h | 5 +++++ MantleTests/MTLCoreDataTestModels.m | 12 ++++++++++++ MantleTests/MTLManagedObjectAdapterSpec.m | 10 ++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Mantle/MTLManagedObjectAdapter.m b/Mantle/MTLManagedObjectAdapter.m index af01edd4..980e0559 100644 --- a/Mantle/MTLManagedObjectAdapter.m +++ b/Mantle/MTLManagedObjectAdapter.m @@ -502,8 +502,8 @@ - (id)managedObjectFromModel:(MTLModel *)model inse } }]; - if (managedObject != nil && ![managedObject validateForInsert:error]) { - performInContext(context, ^ id { + if (managedObject != nil && ![managedObject validateForInsert:&tmpError]) { + managedObject = performInContext(context, ^ id { [context deleteObject:managedObject]; return nil; }); diff --git a/MantleTests/MTLCoreDataTestModels.h b/MantleTests/MTLCoreDataTestModels.h index 9f5efd0f..77b2a8fb 100644 --- a/MantleTests/MTLCoreDataTestModels.h +++ b/MantleTests/MTLCoreDataTestModels.h @@ -23,6 +23,11 @@ @end +// Model for Parent entity which doesn't serialize required properties +@interface MTLParentIncorrectTestModel : MTLModel + +@end + // Corresponds to the `Child` entity. @interface MTLChildTestModel : MTLModel diff --git a/MantleTests/MTLCoreDataTestModels.m b/MantleTests/MTLCoreDataTestModels.m index 0e5b0e50..01dedc0b 100644 --- a/MantleTests/MTLCoreDataTestModels.m +++ b/MantleTests/MTLCoreDataTestModels.m @@ -42,6 +42,18 @@ + (NSDictionary *)relationshipModelClassesByPropertyKey { @end +@implementation MTLParentIncorrectTestModel + ++ (NSString *)managedObjectEntityName { + return @"Parent"; +} + ++ (NSDictionary *)managedObjectKeysByPropertyKey { + return @{}; +} + +@end + @implementation MTLChildTestModel + (NSString *)managedObjectEntityName { diff --git a/MantleTests/MTLManagedObjectAdapterSpec.m b/MantleTests/MTLManagedObjectAdapterSpec.m index f16305cc..78f3c3c9 100644 --- a/MantleTests/MTLManagedObjectAdapterSpec.m +++ b/MantleTests/MTLManagedObjectAdapterSpec.m @@ -226,6 +226,16 @@ expect(error).notTo.beNil(); }); + it(@"should return an error if model doesn't validate for insert", ^{ + MTLParentIncorrectTestModel *parentModel = [MTLParentIncorrectTestModel modelWithDictionary:@{} error:NULL]; + + NSError *error; + NSManagedObject *managedObject = [MTLManagedObjectAdapter managedObjectFromModel:parentModel insertingIntoContext:context error:&error]; + + expect(managedObject).to.beNil(); + expect(error).notTo.beNil(); + }); + it(@"should respect the uniqueness constraint", ^{ NSError *errorOne; MTLParent *parentOne = [MTLManagedObjectAdapter managedObjectFromModel:parentModel insertingIntoContext:context error:&errorOne]; From 61024f83762669da525efc469a126d5ea6e12f48 Mon Sep 17 00:00:00 2001 From: Eli Perkins Date: Mon, 27 Jan 2014 13:33:16 -0500 Subject: [PATCH 07/10] Fixed 'guarantee' typo --- Mantle/MTLManagedObjectAdapter.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mantle/MTLManagedObjectAdapter.m b/Mantle/MTLManagedObjectAdapter.m index 980e0559..4221b813 100644 --- a/Mantle/MTLManagedObjectAdapter.m +++ b/Mantle/MTLManagedObjectAdapter.m @@ -308,7 +308,7 @@ - (id)managedObjectFromModel:(MTLModel *)model inse Class fetchRequestClass = NSClassFromString(@"NSFetchRequest"); NSAssert(fetchRequestClass != nil, @"CoreData.framework must be linked to use MTLManagedObjectAdapter"); - // If a uniquing predicate is provided, perform a fetch request to guarentee a unique managed object. + // If a uniquing predicate is provided, perform a fetch request to guarantee a unique managed object. __block NSManagedObject *managedObject = nil; NSPredicate *uniquingPredicate = [self uniquingPredicateForModel:model]; From 4b7cd967519966c09d62b8294836a623d98914e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20B=C3=B6hnke?= Date: Sat, 1 Feb 2014 16:49:38 +0100 Subject: [PATCH 08/10] ++xcconfigs --- Configuration | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Configuration b/Configuration index 406c5a24..539f0597 160000 --- a/Configuration +++ b/Configuration @@ -1 +1 @@ -Subproject commit 406c5a248491de20421d4935ac5979eba0886996 +Subproject commit 539f059757b2e06417fcc3da90bbbe807137985e From 24a593d02719de3c207cc39df7aae02f9a5a054f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20B=C3=B6hnke?= Date: Sat, 1 Feb 2014 17:23:50 +0100 Subject: [PATCH 09/10] Remove static qualifier from error codes Otherwise Xcode considers them unused variables per -Wunused-const-variable --- Mantle/MTLJSONAdapter.m | 2 +- Mantle/MTLManagedObjectAdapter.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Mantle/MTLJSONAdapter.m b/Mantle/MTLJSONAdapter.m index 6e0772d1..7a5d78dc 100644 --- a/Mantle/MTLJSONAdapter.m +++ b/Mantle/MTLJSONAdapter.m @@ -15,7 +15,7 @@ const NSInteger MTLJSONAdapterErrorInvalidJSONDictionary = 3; // An exception was thrown and caught. -static const NSInteger MTLJSONAdapterErrorExceptionThrown = 1; +const NSInteger MTLJSONAdapterErrorExceptionThrown = 1; // Associated with the NSException that was caught. static NSString * const MTLJSONAdapterThrownExceptionErrorKey = @"MTLJSONAdapterThrownException"; diff --git a/Mantle/MTLManagedObjectAdapter.m b/Mantle/MTLManagedObjectAdapter.m index 4221b813..7a920149 100644 --- a/Mantle/MTLManagedObjectAdapter.m +++ b/Mantle/MTLManagedObjectAdapter.m @@ -35,7 +35,7 @@ static id performInContext(NSManagedObjectContext *context, id (^block)(void)) { } // An exception was thrown and caught. -static const NSInteger MTLManagedObjectAdapterErrorExceptionThrown = 1; +const NSInteger MTLManagedObjectAdapterErrorExceptionThrown = 1; @interface MTLManagedObjectAdapter () From 1862668365e06ead4e83b6cc81c0e2869dc13f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20B=C3=B6hnke?= Date: Sun, 2 Feb 2014 20:13:18 +0100 Subject: [PATCH 10/10] Remove unnecessary error code --- Mantle/MTLManagedObjectAdapter.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/Mantle/MTLManagedObjectAdapter.m b/Mantle/MTLManagedObjectAdapter.m index 7a920149..56ab07b6 100644 --- a/Mantle/MTLManagedObjectAdapter.m +++ b/Mantle/MTLManagedObjectAdapter.m @@ -34,9 +34,6 @@ static id performInContext(NSManagedObjectContext *context, id (^block)(void)) { return result; } -// An exception was thrown and caught. -const NSInteger MTLManagedObjectAdapterErrorExceptionThrown = 1; - @interface MTLManagedObjectAdapter () // The MTLModel subclass being serialized or deserialized.