Alzabo

 view release on metacpan or  search on metacpan

t/05a-rules-mysql.t  view on Meta::CPAN

#!/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::mysql } && ! $@ )
{
    plan skip_all => 'needs DBD::mysql';
    exit;
}

plan tests => 26;


my $new_schema;
eval_ok( sub { $new_schema = Alzabo::Create::Schema->new( name => 'hello there',
                                                          rdbms => 'MySQL' ) },
	 "Make a new MySQL schema named 'hello there'" );

{
    eval { Alzabo::Create::Schema->new( name => 'hello:there',
                                        rdbms => 'MySQL' ); };

    my $e = $@;
    isa_ok( $e, 'Alzabo::Exception::RDBMSRules',
            "Exceptiont thrown from attempt to create a MySQL 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 MySQL with a 65 character name" );
}

my $table;
{
    $table = $new_schema->make_table( name => 'quux' );
    $table->make_column( name => 'foo',
                         type => 'int',
                         attributes => [ 'unsigned' ],
                         null => 1,
                       );

    my $sql = join '', $new_schema->rules->table_sql($table);
    like( $sql, qr/int(?:eger)\s+unsigned/i,
          "Unsigned attribute should come right after type" );
}

{
    eval { $table->make_column( name => 'foo2',
                                type => 'text',
                                length => 1,
                              ); };
    my $e = $@;
    isa_ok( $e, 'Alzabo::Exception::RDBMSRules',



( run in 0.572 second using v1.01-cache-2.11-cpan-f56aa216473 )