Skip to content

Commit

Permalink
Fixed bug with adding 'nil' to async dictionary
Browse files Browse the repository at this point in the history
Spec added
  • Loading branch information
belkevich committed Feb 6, 2014
1 parent e3ce588 commit 7cf305e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Classes/Public/APSmartStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ - (void)objectFromFileWithURL:(NSURL *)url callback:(void (^)(id object, NSError
if (data)
{
id result = weakSelf.parsingBlock ? weakSelf.parsingBlock(data, url) : data;
[weakSelf.memoryStorage setObject:result forURL:url];
if (result)
{
[weakSelf.memoryStorage setObject:result forURL:url];
}
callback(result, nil);
}
else
Expand Down
16 changes: 16 additions & 0 deletions Spec/APSmartStorageSpec/APSmartStorageBaseSpec.mm
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ - (void)objectFromMemoryWithURL:(NSURL *)objectURL callback:(void (^)(id object)
in_time(checkObject) should_not be_nil;
in_time(checkObject) should equal(@"APSmartStorage string");
});

it(@"should not throw exception if block returns nil", ^
{
// parsing block
storage.parsingBlock = ^(NSData *data, NSURL *url)
{
return data ? nil : data;
};
// loading object
__block BOOL isCallbackCalled = NO;
[storage loadObjectWithURL:objectURL callback:^(id object, NSError *error)
{
isCallbackCalled = YES;
}];
in_time(isCallbackCalled) should equal(YES);
});
});

SPEC_END

0 comments on commit 7cf305e

Please sign in to comment.