Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gerhard Schraml
committed
Jan 18, 2010
1 parent
ad5e52a
commit 8273f2b
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Setting.h | ||
// Less2Do | ||
// | ||
// Created by Gerhard Schraml on 18.01.10. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
|
||
@interface Setting : BaseManagedObject { | ||
|
||
} | ||
|
||
@property (nonatomic, retain) NSString * tdEmail; | ||
@property (nonatomic, retain) NSNumber * useTDSync; | ||
|
||
+(Setting*) getSettings:(NSError **)error; | ||
|
||
@end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// Setting.m | ||
// Less2Do | ||
// | ||
// Created by Gerhard Schraml on 18.01.10. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "Setting.h" | ||
|
||
|
||
@implementation Setting | ||
|
||
@dynamic tdEmail; | ||
@dynamic useTDSync; | ||
|
||
+(Setting*) getSettings:(NSError **)error | ||
{ | ||
NSError *fetchError; | ||
|
||
/* get entity description - needed for fetching */ | ||
NSEntityDescription *entityDescription = [NSEntityDescription | ||
entityForName:@"Setting" | ||
inManagedObjectContext:[self managedObjectContext]]; | ||
|
||
/* create new fetch request */ | ||
NSFetchRequest *request = [[NSFetchRequest alloc] init]; | ||
[request setEntity:entityDescription]; | ||
|
||
/* fetch objects */ | ||
NSArray *objects = [[self managedObjectContext] executeFetchRequest:request error:&fetchError]; | ||
if (objects == nil) | ||
{ | ||
*error = [NSError errorWithDomain:DAOErrorDomain code:DAONotFetchedError userInfo:nil]; | ||
[request release]; | ||
|
||
return nil; | ||
} | ||
|
||
[request release]; | ||
|
||
if([objects count] == 0) | ||
{ | ||
*error = [NSError errorWithDomain:DAOErrorDomain code:SettingNotFound userInfo:nil]; | ||
return nil; | ||
} | ||
if([objects count] > 1) | ||
{ | ||
*error = [NSError errorWithDomain:DAOErrorDomain code:SettingMoreThanOne userInfo:nil]; | ||
return nil; | ||
} | ||
|
||
Setting *returnValue = [objects objectAtIndex:0]; | ||
|
||
return returnValue; | ||
} | ||
|
||
@end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// SettingTest.m | ||
// Less2Do | ||
// | ||
// Created by Gerhard Schraml on 18.01.10. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
|
||
|
||
#import "Setting.h" | ||
#import "CustomGHUnitAppDelegate.h"; | ||
|
||
@interface SettingTest : GHTestCase { | ||
NSManagedObjectContext* managedObjectContext; | ||
} | ||
|
||
@end | ||
|
||
@implementation SettingTest | ||
|
||
- (void)setUp { | ||
|
||
/* delete all contexts from the persistent store */ | ||
CustomGHUnitAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; | ||
managedObjectContext = [delegate managedObjectContext]; | ||
|
||
NSFetchRequest *request = [[NSFetchRequest alloc] init]; | ||
[request setEntity:[NSEntityDescription entityForName:@"Setting" inManagedObjectContext:managedObjectContext]]; | ||
|
||
NSError *error; | ||
NSArray *allContexts = [managedObjectContext executeFetchRequest:request error:&error]; | ||
[request release]; | ||
for (NSManagedObject* context in allContexts) | ||
{ | ||
[managedObjectContext deleteObject:context]; | ||
} | ||
if([managedObjectContext save:&error] == NO) | ||
GHFail(@"Error at setUp"); | ||
} | ||
|
||
- (void)tearDown { | ||
/* do nothing */ | ||
ALog(@"got here"); | ||
} | ||
|
||
- (void) testGetSettingsWithoutSettings | ||
{ | ||
NSError *error = nil; | ||
Setting *setting = [Setting getSettings:&error]; | ||
GHAssertNil(setting, @"variable setting should be nil"); | ||
GHAssertEquals([error code], SettingNotFound, @"error should be SettingNotFound"); | ||
} | ||
|
||
-(void) testGetSettings | ||
{ | ||
NSError *error = nil; | ||
Setting *newSetting = (Setting*)[Setting objectOfType:@"Setting"]; | ||
newSetting.tdEmail = @"g.schraml@gmx.at"; | ||
newSetting.useTDSync = [NSNumber numberWithBool:YES]; | ||
[Setting commit]; | ||
Setting *setting = [Setting getSettings:&error]; | ||
GHAssertNotNil(setting, @"setting should arrive here"); | ||
} | ||
|
||
|
||
@end |