Skip to content

Commit

Permalink
See #19. Update the testPushAsset to use the Promise (asynchronous me…
Browse files Browse the repository at this point in the history
…thod) instead of the old non-promise style API.
  • Loading branch information
Glavin001 committed Aug 25, 2014
1 parent 99e6bcc commit de599a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
10 changes: 3 additions & 7 deletions Common/SLStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ - (PMKPromise *) createRecord:(Class<SLModelProtocol>)modelClass withProperties:
[record setupData:properties];
[localContext MR_saveToPersistentStoreAndWait];
record = [record MR_inContext:self.context];
// [self.context MR_saveToPersistentStoreAndWait];
} completion:^(BOOL success, NSError *error) {
NSLog(@"%hhd %@ %@", success, error, record);
if (error) {
Expand All @@ -63,7 +64,6 @@ - (PMKPromise *) createRecord:(Class<SLModelProtocol>)modelClass withProperties:
}];
}


- (PMKPromise *) record:(Class<SLModelProtocol>)modelClass forId:(SLNid)nid
{
return [PMKPromise new:^(PMKPromiseFulfiller fulfiller, PMKPromiseRejecter rejecter) {
Expand All @@ -81,6 +81,7 @@ - (PMKPromise *) record:(Class<SLModelProtocol>)modelClass forId:(SLNid)nid
}
[localContext MR_saveToPersistentStoreAndWait];
record = [record MR_inContext:self.context];
// [self.context MR_saveToPersistentStoreAndWait];
} completion:^(BOOL success, NSError *error) {
NSLog(@"%hhd %@ %@", success, error, record);
if (error) {
Expand Down Expand Up @@ -236,6 +237,7 @@ - (PMKPromise *) push:(Class)modelClass withData:(NSDictionary *)datum
]
]
.then(^(NSArray *results) {

SLModel *record = results[0];
NSDictionary *newDatum = results[1];
NSLog(@"record: %@", record);
Expand All @@ -252,12 +254,6 @@ - (PMKPromise *) push:(Class)modelClass withData:(NSDictionary *)datum
}];
}

//- (PMKPromise *) record:(Class<SLModelProtocol>)modelClass forId:(SLNid)nid withContext:(NSManagedObjectContext *)localContext DEPRECATED_ATTRIBUTE
//{
// PMKPromise *recordPromse = [modelClass recordForId:nid];
// return recordPromise;
//}

- (PMKPromise *) pushMany:(Class)modelClass withData:(NSArray *)data
{
return [PMKPromise new:^(PMKPromiseFulfiller fulfiller, PMKPromiseRejecter rejecter) {
Expand Down
13 changes: 6 additions & 7 deletions Streamlyne-iOS-SDKTests/Streamlyne_iOS_SDKTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ - (void) testPasswordSaving
NSString *encoded = @"99ca2860a3204a9f4e50d6940a67f5ed279f45a9";
NSLog(@"%@ == %@", encoded, [SLAdapter sha1:password]);
XCTAssertStringEqual(encoded, [SLAdapter sha1:password], @"Password should have been correctly encoded.");

NSLog(@"SLLoginPassword: %@", [SLAdapter sha1:SLLoginPassword]);

SLAdapter *manager = [SLAdapter sharedAdapter];
[manager setPassword:@"thisIsATest"];
XCTAssertStringEqual(encoded, manager.userPassword, @"Password should have been encoded when saved.");
Expand Down Expand Up @@ -238,18 +236,19 @@ - (void) testDeserializeSingleAssetPayload

- (void) testPushAsset
{

NSDictionary *pushData = @{
@"nid": @"538770ab2fb05c514e6cb340",
@"dateCreated": [NSDate new],
@"dateUpdated": [NSDate new],
@"desc": @"This is an Asset in a Unit Test.",
@"name": @"PV1234"
};
SLAsset *a1 = (SLAsset *)[[SLStore sharedStore] push:[SLAsset class] withData:pushData];
XCTAssertStringEqual(pushData[@"nid"], a1.nid, @"`nid`s should match.");
XCTAssertStringEqual(pushData[@"desc"], a1.desc, @"`desc`s should match.");
XCTAssertStringEqual(pushData[@"name"], a1.name, @"`name`s should match.");
[[SLStore sharedStore] push:[SLAsset class] withData:pushData]
.then(^( SLAsset *a1) {
XCTAssertStringEqual(pushData[@"nid"], a1.nid, @"`nid`s should match.");
XCTAssertStringEqual(pushData[@"desc"], a1.desc, @"`desc`s should match.");
XCTAssertStringEqual(pushData[@"name"], a1.name, @"`name`s should match.");
});

}

Expand Down

0 comments on commit de599a3

Please sign in to comment.