Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Oct 25, 2015
2 parents 96fbecb + d350f4e commit 49edb0d
Show file tree
Hide file tree
Showing 8 changed files with 758 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Source/Sync.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ + (void)changes:(NSArray *)changes
}
}

if (predicate) {
/*if (predicate) {
NSArray *processedChanges = [changes preprocessForEntityNamed:entityName
usingPredicate:predicate
parent:parent
dataStack:dataStack];
if (processedChanges.count > 0) {
changes = processedChanges;
}
}
}*/

[DATAFilter changes:changes
inEntityNamed:entityName
Expand Down
2 changes: 1 addition & 1 deletion Sync.podspec
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 6 additions & 1 deletion Tests/JSONs/story-summarize.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"id":1,
"summarize_text":{
"id":1
}
},
"comments":[
{
"body":"Hi"
}
]
}
6 changes: 3 additions & 3 deletions Tests/Models/Bug125.xcdatamodeld/Demo.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="8195" systemVersion="15B22c" minimumToolsVersion="Automatic">
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="8195" systemVersion="15B30a" minimumToolsVersion="Automatic">
<entity name="Element" syncable="YES">
<attribute name="label" optional="YES" attributeType="String" syncable="YES">
<userInfo>
<entry key="hyper.isPrimaryKey" value="YES"/>
</userInfo>
</attribute>
<relationship name="element" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Element" inverseName="elements" inverseEntity="Element" syncable="YES"/>
<relationship name="elements" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Element" inverseName="element" inverseEntity="Element" syncable="YES"/>
<relationship name="elements" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="Element" inverseName="element" inverseEntity="Element" syncable="YES"/>
<relationship name="form" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Form" inverseName="element" inverseEntity="Form" syncable="YES"/>
<relationship name="items" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="SelectionItem" inverseName="element" inverseEntity="SelectionItem" syncable="YES"/>
<relationship name="items" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="SelectionItem" inverseName="element" inverseEntity="SelectionItem" syncable="YES"/>
</entity>
<entity name="Form" syncable="YES">
<attribute name="uri" optional="YES" attributeType="String" syncable="YES">
Expand Down
8 changes: 4 additions & 4 deletions Tests/Models/Social.xcdatamodeld/Demo.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="7549" systemVersion="14E7f" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="8195" systemVersion="15B30a" minimumToolsVersion="Automatic">
<entity name="Comment" syncable="YES">
<attribute name="body" optional="YES" attributeType="String" syncable="YES">
<userInfo>
Expand All @@ -21,12 +21,12 @@
</entity>
<entity name="Summarize" syncable="YES">
<attribute name="body" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="remoteID" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="remoteID" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
<relationship name="story" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Story" inverseName="summarize" inverseEntity="Story" syncable="YES"/>
</entity>
<elements>
<element name="Comment" positionX="234" positionY="164" width="128" height="88"/>
<element name="Story" positionX="25" positionY="176" width="128" height="103"/>
<element name="Summarize" positionX="52" positionY="45" width="128" height="88"/>
<element name="Story" positionX="25" positionY="176" width="128" height="105"/>
<element name="Summarize" positionX="52" positionY="45" width="128" height="90"/>
</elements>
</model>
4 changes: 2 additions & 2 deletions Tests/NSArray+Sync_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -23,6 +23,6 @@ - (void)testChangesPreprocessing {
dataStack:dataStack].firstObject;
XCTAssertEqualObjects(preprocessed, formDictionary);
}
}*/

@end
22 changes: 22 additions & 0 deletions Tests/SyncTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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];
Expand Down Expand Up @@ -696,6 +701,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];
}

Expand Down
Loading

0 comments on commit 49edb0d

Please sign in to comment.