Created
January 29, 2014 02:14
-
-
Save westonplatter/8680606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void) testRelationshipTodoUser | |
| { | |
| // Create user and todo | |
| User *user = [NSEntityDescription insertNewObjectForEntityForName:@"User" inManagedObjectContext:self.moc]; | |
| [user setEmail:@"[email protected]"]; | |
| Todo *todo = [NSEntityDescription insertNewObjectForEntityForName:@"Todo" inManagedObjectContext:self.moc]; | |
| [todo setAction:@"first"]; | |
| [todo setUser:user]; | |
| NSError *error = nil; | |
| BOOL result = [self.moc save:&error]; | |
| XCTAssertNil(error, @"save should not raise errors"); | |
| XCTAssertTrue(result, @"save should be true"); | |
| // Fetch todo and get user | |
| NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; | |
| NSEntityDescription *todoEntity = [NSEntityDescription entityForName:@"Todo" inManagedObjectContext:self.moc]; | |
| [fetchRequest setEntity:todoEntity]; | |
| NSArray *fetchedObjects = [self.moc executeFetchRequest:fetchRequest error:&error]; | |
| NSObject *fetchedTodo = [fetchedObjects firstObject]; | |
| NSObject *fetchedUser = [fetchedTodo valueForKey:@"user"]; | |
| NSString *email = [fetchedUser valueForKey:@"email"]; | |
| // Check that email is the same as set value | |
| XCTAssert([email isEqualToString:@"[email protected]"], @"user should have email"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment