Skip to content

Commit

Permalink
All deprecated and non-deprecated methods have tests to ensure their …
Browse files Browse the repository at this point in the history
…function
  • Loading branch information
tonyarnold committed Dec 16, 2012
1 parent 2c66056 commit c2fa8c4
Show file tree
Hide file tree
Showing 6 changed files with 702 additions and 171 deletions.
Expand Up @@ -32,14 +32,14 @@ typedef void (^MRSaveCompletionHandler)(BOOL success, NSError *error);
* The following methods are deprecated, but remain in place for backwards compatibility until the next major version (3.x)
*/
- (void) MR_save __attribute__((deprecated));
- (void) MR_saveWithErrorCallback:(void(^)(NSError *))errorCallback __attribute__((deprecated));
- (void) MR_saveWithErrorCallback:(void(^)(NSError *error))errorCallback __attribute__((deprecated));

- (void) MR_saveInBackgroundCompletion:(void (^)(void))completion __attribute__((deprecated));
- (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback __attribute__((deprecated));
- (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback completion:(void (^)(void))completion __attribute__((deprecated));
- (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *error))errorCallback __attribute__((deprecated));
- (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *error))errorCallback completion:(void (^)(void))completion __attribute__((deprecated));

- (void) MR_saveNestedContexts __attribute__((deprecated));
- (void) MR_saveNestedContextsErrorHandler:(void (^)(NSError *))errorCallback __attribute__((deprecated));
- (void) MR_saveNestedContextsErrorHandler:(void (^)(NSError *))errorCallback completion:(void (^)(void))completion __attribute__((deprecated));
- (void) MR_saveNestedContextsErrorHandler:(void (^)(NSError *error))errorCallback __attribute__((deprecated));
- (void) MR_saveNestedContextsErrorHandler:(void (^)(NSError *error))errorCallback completion:(void (^)(void))completion __attribute__((deprecated));

@end
Expand Up @@ -50,6 +50,8 @@ - (void)MR_saveWithOptions:(MRSaveContextOptions)mask completion:(MRSaveCompleti
}

MRLog(@"→ Saving %@", [self MR_description]);
MRLog(@"→ Save Parents? %@", @(saveParentContexts));
MRLog(@"→ Save Synchronously? %@", @(syncSave));

id saveBlock = ^{
NSError *error = nil;
Expand Down Expand Up @@ -102,14 +104,17 @@ - (void)MR_saveWithOptions:(MRSaveContextOptions)mask completion:(MRSaveCompleti
#pragma mark - Deprecated methods
// These methods will be removed in MagicalRecord 3.0

- (void)MR_saveNestedContexts;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"

- (void)MR_save;
{
[self MR_saveToPersistentStoreWithCompletion:nil];
[self MR_saveToPersistentStoreAndWait];
}

- (void)MR_saveNestedContextsErrorHandler:(void (^)(NSError *))errorCallback;
- (void)MR_saveWithErrorCallback:(void (^)(NSError *error))errorCallback;
{
[self MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {
[self MR_saveWithOptions:MRSaveSynchronously|MRSaveParentContexts completion:^(BOOL success, NSError *error) {
if (!success) {
if (errorCallback) {
errorCallback(error);
Expand All @@ -118,30 +123,20 @@ - (void)MR_saveNestedContextsErrorHandler:(void (^)(NSError *))errorCallback;
}];
}

- (void)MR_saveNestedContextsErrorHandler:(void (^)(NSError *))errorCallback completion:(void (^)(void))completion;
- (void)MR_saveInBackgroundCompletion:(void (^)(void))completion;
{
[self MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {
[self MR_saveOnlySelfWithCompletion:^(BOOL success, NSError *error) {
if (success) {
if (completion) {
completion();
}
} else {
if (errorCallback) {
errorCallback(error);
}
}
}];
}

- (void)MR_save;
- (void)MR_saveInBackgroundErrorHandler:(void (^)(NSError *error))errorCallback;
{
[self MR_saveToPersistentStoreAndWait];
}

- (void)MR_saveWithErrorCallback:(void (^)(NSError *))errorCallback __attribute__((deprecated));

{
[self MR_saveWithOptions:MRSaveSynchronously completion:^(BOOL success, NSError *error) {
[self MR_saveOnlySelfWithCompletion:^(BOOL success, NSError *error) {
if (!success) {
if (errorCallback) {
errorCallback(error);
Expand All @@ -150,20 +145,29 @@ - (void)MR_saveWithErrorCallback:(void (^)(NSError *))errorCallback __attribute_
}];
}

- (void)MR_saveInBackgroundCompletion:(void (^)(void))completion;
- (void)MR_saveInBackgroundErrorHandler:(void (^)(NSError *error))errorCallback completion:(void (^)(void))completion;
{
[self MR_saveOnlySelfWithCompletion:^(BOOL success, NSError *error) {
if (success) {
if (completion) {
completion();
}
} else {
if (errorCallback) {
errorCallback(error);
}
}
}];
}

- (void)MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback;
- (void)MR_saveNestedContexts;
{
[self MR_saveOnlySelfWithCompletion:^(BOOL success, NSError *error) {
[self MR_saveToPersistentStoreWithCompletion:nil];
}

- (void)MR_saveNestedContextsErrorHandler:(void (^)(NSError *error))errorCallback;
{
[self MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {
if (!success) {
if (errorCallback) {
errorCallback(error);
Expand All @@ -172,9 +176,9 @@ - (void)MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback;
}];
}

- (void)MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback completion:(void (^)(void))completion;
- (void)MR_saveNestedContextsErrorHandler:(void (^)(NSError *error))errorCallback completion:(void (^)(void))completion;
{
[self MR_saveOnlySelfWithCompletion:^(BOOL success, NSError *error) {
[self MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {
if (success) {
if (completion) {
completion();
Expand All @@ -187,4 +191,6 @@ - (void)MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback compl
}];
}

#pragma clang diagnostic pop // ignored "-Wdeprecated-implementations"

@end
2 changes: 1 addition & 1 deletion MagicalRecord/Core/MagicalRecord+Actions.h
Expand Up @@ -39,6 +39,6 @@
/*
If you want to reuse the context on the current thread, use this method.
*/
+ (void) saveInBackgroundUsingCurrentContextWithBlock:(void (^)(NSManagedObjectContext *localContext))block completion:(void (^)(void))completion errorHandler:(void (^)(NSError *))errorHandler __attribute__((deprecated));
+ (void) saveInBackgroundUsingCurrentContextWithBlock:(void (^)(NSManagedObjectContext *localContext))block completion:(void (^)(void))completion errorHandler:(void (^)(NSError *error))errorHandler __attribute__((deprecated));

@end
8 changes: 6 additions & 2 deletions MagicalRecord/Core/MagicalRecord+Actions.m
Expand Up @@ -78,6 +78,9 @@ + (void) saveUsingCurrentThreadContextWithBlockAndWait:(void (^)(NSManagedObject

#pragma mark - Deprecated methods

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"

+ (void) saveInBackgroundWithBlock:(void(^)(NSManagedObjectContext *localContext))block
{
[[self class] saveWithBlock:block completion:nil];
Expand All @@ -103,7 +106,7 @@ + (void) saveInBackgroundWithBlock:(void(^)(NSManagedObjectContext *localContext
}];
}

+ (void) saveInBackgroundUsingCurrentContextWithBlock:(void (^)(NSManagedObjectContext *localContext))block completion:(void (^)(void))completion errorHandler:(void (^)(NSError *))errorHandler;
+ (void) saveInBackgroundUsingCurrentContextWithBlock:(void (^)(NSManagedObjectContext *localContext))block completion:(void (^)(void))completion errorHandler:(void (^)(NSError *error))errorHandler;
{
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];

Expand All @@ -113,7 +116,6 @@ + (void) saveInBackgroundUsingCurrentContextWithBlock:(void (^)(NSManagedObjectC
}

[localContext MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {

if (success) {
if (completion) {
completion();
Expand All @@ -128,4 +130,6 @@ + (void) saveInBackgroundUsingCurrentContextWithBlock:(void (^)(NSManagedObjectC
}];
}

#pragma clang diagnostic pop // ignored "-Wdeprecated-implementations"

@end

0 comments on commit c2fa8c4

Please sign in to comment.