From: Rafael Kitover Date: Wed, 12 Aug 2009 11:26:13 +0000 (+0000) Subject: fix mysql tests for CURRENT_TIMESTAMP X-Git-Tag: 0.04999_08~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e0699cd9360abcf912874e6020dc5dfe164c3d9e;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix mysql tests for CURRENT_TIMESTAMP --- diff --git a/t/11mysql_common.t b/t/11mysql_common.t index bd86d93..f917c90 100644 --- a/t/11mysql_common.t +++ b/t/11mysql_common.t @@ -28,9 +28,16 @@ my $tester = dbixcsl_common_tests->new( value ENUM('foo', 'bar', 'baz') ) }, + qq{ + CREATE TABLE mysql_loader_test2 ( + id INTEGER UNSIGNED NOT NULL PRIMARY KEY, + somedate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + somestr VARCHAR(100) NOT NULL DEFAULT 'foo' + ) + }, ], - drop => [ qw/ mysql_loader_test1 / ], - count => 3, + drop => [ qw/ mysql_loader_test1 mysql_loader_test2 / ], + count => 5, run => sub { my ($schema, $monikers, $classes) = @_; @@ -44,6 +51,14 @@ my $tester = dbixcsl_common_tests->new( like($column_info->{data_type}, qr/^enum$/i, 'MySQL ENUM type'); is_deeply($column_info->{extra}->{list}, [qw/foo bar baz/], 'MySQL ENUM values'); + + $rs = $schema->resultset($monikers->{mysql_loader_test2}); + my $column_info = $rs->result_source->column_info('somedate'); + my $default = $column_info->{default_value}; + ok (ref($default) eq 'SCALAR'), + 'CURRENT_TIMESTAMP default_value is a scalar ref'; + like $$default, qr/^CURRENT_TIMESTAMP\z/i, + 'CURRENT_TIMESTAMP default eq "CURRENT_TIMESTAMP"'; }, } ); diff --git a/t/11mysql_current_timestamp.t b/t/11mysql_current_timestamp.t deleted file mode 100644 index 8672f42..0000000 --- a/t/11mysql_current_timestamp.t +++ /dev/null @@ -1,71 +0,0 @@ -use strict; -use lib qw(t/lib); -use Test::More; -use DBI; - -my $DUMP_DIR; -BEGIN { - $DUMP_DIR = './t/_common_dump'; -} - -use lib $DUMP_DIR; -use DBIx::Class::Schema::Loader 'make_schema_at', "dump_to_dir:$DUMP_DIR"; -use File::Path; -use Test::Exception; - -my ($dsn, $user, $password) = map $ENV{"DBICTEST_MYSQL_$_"}, qw/DSN USER PASS/; - -if( !$dsn || !$user ) { - plan skip_all => 'You need to set the DBICTEST_MYSQL_DSN, _USER, and _PASS' - .' environment variables'; -} - -eval "use SQL::Translator '0.09007';"; -plan skip_all => 'SQL::Translator 0.09007 or greater required' - if $@; - -plan tests => 2; - -my $dbh = DBI->connect($dsn, $user, $password, { - RaiseError => 1, PrintError => 0 -}); - -eval { $dbh->do('DROP TABLE loadertest') }; -$dbh->do(q{ - CREATE TABLE loadertest ( - id INT PRIMARY KEY, - somedate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - somestr VARCHAR(100) NOT NULL DEFAULT 'foo' - ) Engine=InnoDB -}); -# XXX there needs to be code to distinguish these two types of defaults - -rmtree $DUMP_DIR; - -make_schema_at( - 'TestSL::Schema', - { - use_namespaces => 1, - constraint => qr/^loadertest\z/ - }, - [ $dsn, $user, $password, ] -); - -lives_ok { require TestSL::Schema } 'schema loads'; - -$dbh->do('DROP TABLE loadertest'); - -my $schema = TestSL::Schema->connect($dsn, $user, $password); - -my @warnings; -local $SIG{__WARN__} = sub { push @warnings, shift }; - -$schema->deploy; - -ok (not(grep /Invalid default/, @warnings)), 'default deployed'; -diag $_ for @warnings; - -END { - rmtree $DUMP_DIR; - eval { $dbh->do('DROP TABLE loadertest') }; -}