Skip to content

Commit

Permalink
can create new tables
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Sep 6, 2008
1 parent bef8ef2 commit ec7578b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Classes/FmdbMigrationManager.h
Expand Up @@ -10,7 +10,10 @@
#import "FMDatabase.h"

@interface FmdbMigrationManager : NSObject {

FMDatabase *db;
}
@property (retain) FMDatabase *db;

- (id)initWithDatabase:(FMDatabase *)sqliteDatabase;
- (void)createTable:(NSString *)tableName;
@end
14 changes: 14 additions & 0 deletions Classes/FmdbMigrationManager.m
Expand Up @@ -11,6 +11,20 @@

@implementation FmdbMigrationManager

@synthesize db;

- (id)initWithDatabase:(FMDatabase *)sqliteDatabase {
if ([super init]) {
db = sqliteDatabase;
return self;
}
return nil;
}

- (void)createTable:(NSString *)tableName {
NSString *cmd = [@"create table " stringByAppendingString:tableName];
[db executeUpdate:[cmd stringByAppendingString:@" (id integer)"]];
}
@end


Expand Down
40 changes: 37 additions & 3 deletions test/test_fmdb_migration_manager.rb
Expand Up @@ -15,13 +15,47 @@ class TestFmdbMigrationManager < Test::Unit::TestCase
@db.open
end

teardown do
FileUtils.rm @db_path if File.exists?(@db_path)
end
teardown { FileUtils.rm @db_path if File.exists?(@db_path) }

should "create sqlite db" do
assert File.exists?(@db_path)
end

should "have no initial errors" do
assert(!@db.hadError?, "Last error (#{@db.lastErrorCode}): #{@db.lastErrorMessage}")
end

context "prepare for migrations" do
setup do
@migration_manager = OSX::FmdbMigrationManager.alloc.initWithDatabase(@db)
end

should "have migration manager" do
assert_not_nil(@migration_manager)
assert_instance_of(OSX::FmdbMigrationManager, @migration_manager)
end

context "then create table with no explicit columns" do
setup do
@m1 = @migration_manager.createTable("people")
@results = @db.executeQuery "select * from people"
end

teardown { @results.close if @results }

should "not cause errors" do
assert(!@db.hadError?, "Last error (#{@db.lastErrorCode}): #{@db.lastErrorMessage}")
end

should "have table 'people'" do
assert_not_nil(@results)
assert_instance_of(OSX::FMResultSet, @results)
assert(!@results.next?, "Should be no results")
end
end

end

end

end

0 comments on commit ec7578b

Please sign in to comment.