Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Tests - Checking the background queue #777

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/MagicalRecordStack/MagicalRecordStack+Actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dispatch_queue_t MR_saveQueue(void);
/**
* Synchronously saves the default managed object context (if there is one) and any parent contexts.
*
* @param block Make changes to CoreData objects in this block using the passed in localContext. The block will be performed on a background queue, and once complete, the context will be saved.
* @param block Make changes to CoreData objects in this block using the passed in localContext. The block itself is not guaranteed to run on any particular background thread/queue, and once complete, the context will be saved.
*
* @return Success state of the save operation
*/
Expand All @@ -37,7 +37,7 @@ dispatch_queue_t MR_saveQueue(void);
*
* Synchronously saves the default managed object context (if there is one) and any parent contexts.
*
* @param block Make changes to CoreData objects in this block using the passed in localContext. The block will be performed on a background queue, and once complete, the context will be saved.
* @param block Make changes to CoreData objects in this block using the passed in localContext. The block itself is not guaranteed to run on any particular background thread/queue, the context will be saved.
* @param error Pass in an NSError by reference to receive any errors encountered during the save.
*
* @return Whether the save was successful
Expand Down
12 changes: 12 additions & 0 deletions Tests/Core/MagicalRecord+ActionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,16 @@ - (void)testAsynchronousSaveActionMakesUpdatesToEntitiesAvailableToTheDefaultCon
expect([fetchedObject valueForKey:kTestAttributeKey]).will.beFalsy();
}

- (void)testAsynchronousSaveActionPerformedOnBackgroundQueue
{
MagicalRecordStack *currentStack = self.stack;

[currentStack saveWithBlock:^(NSManagedObjectContext *localContext) {
expect([NSThread currentThread]).toNot.equal([NSThread mainThread]);

} completion:^(BOOL success, NSError *error) {
expect([NSThread currentThread]).to.equal([NSThread mainThread]);
}];
}

@end