From 18b6a4c8cce0357f73d7243fe2a0d68dd04ad083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= Date: Tue, 13 Oct 2015 15:55:53 +0200 Subject: [PATCH 1/9] Improve tests and rollback processedChanges --- Source/Sync.m | 4 ++-- Tests/Tests.xcodeproj/project.pbxproj | 2 +- Tests/Tests/JSONs/story-summarize.json | 7 ++++++- .../Demo.xcdatamodel/contents | 6 +++--- .../Demo.xcdatamodel/contents | 8 ++++---- Tests/Tests/NSArray+Sync_Tests.m | 4 ++-- Tests/Tests/SyncTests.m | 17 +++++++++++++++++ 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Source/Sync.m b/Source/Sync.m index 67b10a83..4d31c8b4 100755 --- a/Source/Sync.m +++ b/Source/Sync.m @@ -87,7 +87,7 @@ + (void)changes:(NSArray *)changes } } - if (predicate) { + /*if (predicate) { NSArray *processedChanges = [changes preprocessForEntityNamed:entityName usingPredicate:predicate parent:parent @@ -95,7 +95,7 @@ + (void)changes:(NSArray *)changes if (processedChanges.count > 0) { changes = processedChanges; } - } + }*/ [DATAFilter changes:changes inEntityNamed:entityName diff --git a/Tests/Tests.xcodeproj/project.pbxproj b/Tests/Tests.xcodeproj/project.pbxproj index 237b5361..3cf36b23 100755 --- a/Tests/Tests.xcodeproj/project.pbxproj +++ b/Tests/Tests.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 0374412F80C6B8D5200C882C /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6C99E9E23EA886944E25CF9 /* Pods.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; + 0374412F80C6B8D5200C882C /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6C99E9E23EA886944E25CF9 /* Pods.framework */; }; 141603011BC32307007D0600 /* NSArray+Sync.m in Sources */ = {isa = PBXBuildFile; fileRef = 141603001BC32307007D0600 /* NSArray+Sync.m */; settings = {ASSET_TAGS = (); }; }; 141603031BC32425007D0600 /* NSArray+Sync_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 141603021BC32425007D0600 /* NSArray+Sync_Tests.m */; settings = {ASSET_TAGS = (); }; }; 14584B041B7EE38600293841 /* Bug113.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 14584B021B7EE38600293841 /* Bug113.xcdatamodeld */; }; diff --git a/Tests/Tests/JSONs/story-summarize.json b/Tests/Tests/JSONs/story-summarize.json index 705a32b9..a97d2779 100644 --- a/Tests/Tests/JSONs/story-summarize.json +++ b/Tests/Tests/JSONs/story-summarize.json @@ -2,5 +2,10 @@ "id":1, "summarize_text":{ "id":1 - } + }, + "comments":[ + { + "body":"Hi" + } + ] } diff --git a/Tests/Tests/Models/Bug125.xcdatamodeld/Demo.xcdatamodel/contents b/Tests/Tests/Models/Bug125.xcdatamodeld/Demo.xcdatamodel/contents index 6046cbfa..e4e32374 100644 --- a/Tests/Tests/Models/Bug125.xcdatamodeld/Demo.xcdatamodel/contents +++ b/Tests/Tests/Models/Bug125.xcdatamodeld/Demo.xcdatamodel/contents @@ -1,5 +1,5 @@ - + @@ -7,9 +7,9 @@ - + - + diff --git a/Tests/Tests/Models/Social.xcdatamodeld/Demo.xcdatamodel/contents b/Tests/Tests/Models/Social.xcdatamodeld/Demo.xcdatamodel/contents index 70326515..d1c46770 100644 --- a/Tests/Tests/Models/Social.xcdatamodeld/Demo.xcdatamodel/contents +++ b/Tests/Tests/Models/Social.xcdatamodeld/Demo.xcdatamodel/contents @@ -1,5 +1,5 @@ - + @@ -21,12 +21,12 @@ - + - - + + \ No newline at end of file diff --git a/Tests/Tests/NSArray+Sync_Tests.m b/Tests/Tests/NSArray+Sync_Tests.m index 2f30a679..40765f29 100644 --- a/Tests/Tests/NSArray+Sync_Tests.m +++ b/Tests/Tests/NSArray+Sync_Tests.m @@ -11,7 +11,7 @@ @implementation NSArray_Sync_Tests #pragma mark Bug 125 => https://github.com/hyperoslo/Sync/issues/125 -- (void)testChangesPreprocessing { +/*- (void)testChangesPreprocessing { NSDictionary *formDictionary = [self objectsFromJSON:@"bug-125-light.json"]; NSString *uri = formDictionary[@"uri"]; @@ -23,6 +23,6 @@ - (void)testChangesPreprocessing { dataStack:dataStack].firstObject; XCTAssertEqualObjects(preprocessed, formDictionary); -} +}*/ @end diff --git a/Tests/Tests/SyncTests.m b/Tests/Tests/SyncTests.m index 7c2f19c9..90653477 100755 --- a/Tests/Tests/SyncTests.m +++ b/Tests/Tests/SyncTests.m @@ -696,6 +696,23 @@ - (void)testStoryToSummarize { dataStack:dataStack completion:nil]; + XCTAssertEqual([self countForEntity:@"Story" + inContext:dataStack.mainContext], 1); + NSArray *stories = [self fetchEntity:@"Story" + predicate:[NSPredicate predicateWithFormat:@"remoteID = %@", @1] + inContext:dataStack.mainContext]; + NSManagedObject *story = [stories firstObject]; + NSManagedObject *summarize = [story valueForKey:@"summarize"]; + XCTAssertEqualObjects([summarize valueForKey:@"remoteID"], @1); + XCTAssertEqual([[story valueForKey:@"comments"] count], 1); + + XCTAssertEqual([self countForEntity:@"Comment" + inContext:dataStack.mainContext], 1); + NSArray *comments = [self fetchEntity:@"Comment" + predicate:[NSPredicate predicateWithFormat:@"body = %@", @"Hi"] + inContext:dataStack.mainContext]; + XCTAssertEqual(comments.count, 1); + [dataStack drop]; } From f95f01dd38dc9f46a5cd0120bacc899200378317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= <3lvis@users.noreply.github.com> Date: Tue, 13 Oct 2015 16:13:32 +0200 Subject: [PATCH 2/9] Update Sync.podspec --- Sync.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sync.podspec b/Sync.podspec index 8b10d8a7..b6e006f6 100755 --- a/Sync.podspec +++ b/Sync.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Sync" -s.version = "1.1.0" +s.version = "1.1.1" s.summary = "Modern JSON synchronization to Core Data" s.description = <<-DESC This is a category that eases your every day job of parsing an API and getting it into Core Data. @@ -22,7 +22,7 @@ s.source_files = 'Source/**/*' s.frameworks = 'Foundation', 'CoreData' -s.dependency 'DATAFilter', '~> 0.8.4' +s.dependency 'DATAFilter', '~> 0.9.0' s.dependency 'DATAStack', '~> 3.1.2' s.dependency 'NSDictionary-ANDYSafeValue', '~> 0.3' s.dependency 'NSEntityDescription-SYNCPrimaryKey', '~> 0.1.0' From 7c624fb296ffcab0ff3284f4c07d54e75876cdc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= Date: Tue, 13 Oct 2015 16:18:07 +0200 Subject: [PATCH 3/9] Migrate to DATAFilter 0.9.0 --- Source/Sync.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Sync.m b/Source/Sync.m index 4d31c8b4..9f96f197 100755 --- a/Source/Sync.m +++ b/Source/Sync.m @@ -99,10 +99,11 @@ + (void)changes:(NSArray *)changes [DATAFilter changes:changes inEntityNamed:entityName + predicate:predicate + operations:DATAFilterOperationAll localKey:localKey remoteKey:remoteKey context:context - predicate:predicate inserted:^(NSDictionary *objectJSON) { NSError *error = nil; NSManagedObject *created = [NSEntityDescription insertNewObjectForEntityForName:entityName From ae364211641fc7aee431aa3b9d70648fcf2fcbad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= Date: Thu, 15 Oct 2015 14:23:48 +0200 Subject: [PATCH 4/9] Add silly comments to test --- Tests/Tests/SyncTests.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/Tests/SyncTests.m b/Tests/Tests/SyncTests.m index 90653477..9b67e9cb 100755 --- a/Tests/Tests/SyncTests.m +++ b/Tests/Tests/SyncTests.m @@ -163,6 +163,8 @@ - (void)testObjectsForParent { DATAStack *dataStack = [self dataStackWithModelName:@"Notes"]; [dataStack performInNewBackgroundContext:^(NSManagedObjectContext *backgroundContext) { + + // First, we create a parent user, this user is the one that will own all the notes NSManagedObject *user = [NSEntityDescription insertNewObjectForEntityForName:@"User" inManagedObjectContext:backgroundContext]; [user setValue:@6 forKey:@"remoteID"]; @@ -176,17 +178,20 @@ - (void)testObjectsForParent { [dataStack persistWithCompletion:nil]; }]; + // Then we fetch the user on the main context, because we don't want to break things between contexts NSArray *users = [self fetchEntity:@"User" predicate:[NSPredicate predicateWithFormat:@"remoteID = %@", @6] inContext:dataStack.mainContext]; if (users.count != 1) abort(); + // Finally we say "Sync all the notes, for this user" [Sync changes:objects inEntityNamed:@"Note" parent:[users firstObject] dataStack:dataStack completion:nil]; + // Here we just make sure that the user has the notes that we just inserted users = [self fetchEntity:@"User" predicate:[NSPredicate predicateWithFormat:@"remoteID = %@", @6] inContext:dataStack.mainContext]; From c8712748dedd4062a115e9490d87a19b2ddfd61e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= <3lvis@users.noreply.github.com> Date: Sat, 24 Oct 2015 12:52:01 +0200 Subject: [PATCH 5/9] Update Sync.podspec --- Sync.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sync.podspec b/Sync.podspec index b6e006f6..3113d00c 100755 --- a/Sync.podspec +++ b/Sync.podspec @@ -25,6 +25,6 @@ s.frameworks = 'Foundation', 'CoreData' s.dependency 'DATAFilter', '~> 0.9.0' s.dependency 'DATAStack', '~> 3.1.2' s.dependency 'NSDictionary-ANDYSafeValue', '~> 0.3' -s.dependency 'NSEntityDescription-SYNCPrimaryKey', '~> 0.1.0' +s.dependency 'NSEntityDescription-SYNCPrimaryKey', '~> 0.1.1' s.dependency 'NSManagedObject-HYPPropertyMapper', '~> 3.3.2' end From 24a74f143b0d157bbe2cdbdc3e96e5afec1d36fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= <3lvis@users.noreply.github.com> Date: Sat, 24 Oct 2015 12:52:21 +0200 Subject: [PATCH 6/9] Update Sync.podspec --- Sync.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sync.podspec b/Sync.podspec index 3113d00c..587ee873 100755 --- a/Sync.podspec +++ b/Sync.podspec @@ -22,7 +22,7 @@ s.source_files = 'Source/**/*' s.frameworks = 'Foundation', 'CoreData' -s.dependency 'DATAFilter', '~> 0.9.0' +s.dependency 'DATAFilter', '~> 0.9.1' s.dependency 'DATAStack', '~> 3.1.2' s.dependency 'NSDictionary-ANDYSafeValue', '~> 0.3' s.dependency 'NSEntityDescription-SYNCPrimaryKey', '~> 0.1.1' From 675ad4af4a769c46dcd584073ce7e575fa5d2adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= <3lvis@users.noreply.github.com> Date: Sat, 24 Oct 2015 12:52:45 +0200 Subject: [PATCH 7/9] Update Sync.podspec --- Sync.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sync.podspec b/Sync.podspec index 587ee873..a8034621 100755 --- a/Sync.podspec +++ b/Sync.podspec @@ -23,7 +23,7 @@ s.source_files = 'Source/**/*' s.frameworks = 'Foundation', 'CoreData' s.dependency 'DATAFilter', '~> 0.9.1' -s.dependency 'DATAStack', '~> 3.1.2' +s.dependency 'DATAStack', '~> 4.0.1' s.dependency 'NSDictionary-ANDYSafeValue', '~> 0.3' s.dependency 'NSEntityDescription-SYNCPrimaryKey', '~> 0.1.1' s.dependency 'NSManagedObject-HYPPropertyMapper', '~> 3.3.2' From 02e8b19880f54ef573f573df78dd49b162a1bd66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= <3lvis@users.noreply.github.com> Date: Sat, 24 Oct 2015 12:53:07 +0200 Subject: [PATCH 8/9] Update Sync.podspec --- Sync.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sync.podspec b/Sync.podspec index a8034621..c048d30b 100755 --- a/Sync.podspec +++ b/Sync.podspec @@ -24,7 +24,7 @@ s.frameworks = 'Foundation', 'CoreData' s.dependency 'DATAFilter', '~> 0.9.1' s.dependency 'DATAStack', '~> 4.0.1' -s.dependency 'NSDictionary-ANDYSafeValue', '~> 0.3' +s.dependency 'NSDictionary-ANDYSafeValue', '~> 0.3.1' s.dependency 'NSEntityDescription-SYNCPrimaryKey', '~> 0.1.1' s.dependency 'NSManagedObject-HYPPropertyMapper', '~> 3.3.2' end From d350f4e641f8bf8c16265b7d16089e10fbd4bc6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= <3lvis@users.noreply.github.com> Date: Sat, 24 Oct 2015 12:54:18 +0200 Subject: [PATCH 9/9] Update Sync.podspec --- Sync.podspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sync.podspec b/Sync.podspec index c048d30b..b6e006f6 100755 --- a/Sync.podspec +++ b/Sync.podspec @@ -22,9 +22,9 @@ s.source_files = 'Source/**/*' s.frameworks = 'Foundation', 'CoreData' -s.dependency 'DATAFilter', '~> 0.9.1' -s.dependency 'DATAStack', '~> 4.0.1' -s.dependency 'NSDictionary-ANDYSafeValue', '~> 0.3.1' -s.dependency 'NSEntityDescription-SYNCPrimaryKey', '~> 0.1.1' +s.dependency 'DATAFilter', '~> 0.9.0' +s.dependency 'DATAStack', '~> 3.1.2' +s.dependency 'NSDictionary-ANDYSafeValue', '~> 0.3' +s.dependency 'NSEntityDescription-SYNCPrimaryKey', '~> 0.1.0' s.dependency 'NSManagedObject-HYPPropertyMapper', '~> 3.3.2' end