Skip to content

Commit

Permalink
added settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerhard Schraml committed Jan 18, 2010
1 parent ad5e52a commit 8273f2b
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Classes/Setting.h
@@ -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
58 changes: 58 additions & 0 deletions Classes/Setting.m
@@ -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
67 changes: 67 additions & 0 deletions SettingTest.m
@@ -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

0 comments on commit 8273f2b

Please sign in to comment.