1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#!/usr/bin/perl -w
use strict;
use File::Spec;
use lib '.', File::Spec->catdir( File::Spec->curdir, 't', 'lib' );
use Alzabo::Test::Utils;
use Test::More;
use Alzabo::Create;
unless ( eval { require DBD::Pg } && ! $@ )
{
plan skip_all => 'needs DBD::Pg';
exit;
}
plan tests => 10;
my $new_schema;
eval_ok( sub { $new_schema = Alzabo::Create::Schema->new( name => 'hello_there',
rdbms => 'PostgreSQL' ) },
"Make a new PostgreSQL schema named 'hello_there'" );
{
eval { Alzabo::Create::Schema->new( name => "hello'there",
rdbms => 'PostgreSQL' ); };
my $e = $@;
isa_ok( $e, 'Alzabo::Exception::RDBMSRules',
"Exceptiont thrown from attempt to create a PostgreSQL schema named hello\'there" );
}
{
eval { $new_schema->make_table( name => 'x' x 65 ) };
my $e = $@;
isa_ok( $e, 'Alzabo::Exception::RDBMSRules',
"Exception thrown from attempt to create a table in PostgreSQL with a 65 character name" );
}
my $table = $new_schema->make_table( name => 'quux' );
{
eval { $table->make_column( name => 'foo2',
type => 'text',
length => 1,
); };
my $e = $@;
isa_ok( $e, 'Alzabo::Exception::RDBMSRules',
"Exception thrown from attempt to make 'text' column with a length parameter" );
}
{
foreach my $type ( qw( DATE TIMESTAMP TIMESTAMPTZ ) )
{
my $col = $table->make_column( name => "col_$type",
type => $type,
);
ok( $col->is_date, "$type is date" );
};
}
{
foreach my $type ( qw( TIMESTAMP TIMESTAMPTZ ) )
{
my $col = $table->make_column( name => "col2_$type",
type => $type,
);
ok( $col->is_datetime, "$type is date" );
};
}
{
my $col = $table->make_column( name => 'col_INTERVAL',
type => 'INTERVAL',
);
ok( $col->is_time_interval, 'INTERVAL is a time interval' );
}
|