From: Rafael Kitover Date: Thu, 4 Mar 2010 19:59:54 +0000 (-0500) Subject: mssql: clean up extra tests X-Git-Tag: 0.06000~65 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=80a212f5f65cdd0098744b3ff5498250dab205d2;p=dbsrgits%2FDBIx-Class-Schema-Loader.git mssql: clean up extra tests --- diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 30710e9..e1ee1ce 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -210,6 +210,8 @@ sub test_schema { foreach my $source_name ($schema_class->sources) { my $table_name = $schema_class->source($source_name)->from; + $table_name = $$table_name if ref $table_name; + $monikers->{$table_name} = $source_name; $classes->{$table_name} = $schema_class . q{::} . $source_name; diff --git a/t/lib/dbixcsl_mssql_extra_tests.pm b/t/lib/dbixcsl_mssql_extra_tests.pm index bafe790..e4767f9 100644 --- a/t/lib/dbixcsl_mssql_extra_tests.pm +++ b/t/lib/dbixcsl_mssql_extra_tests.pm @@ -1,59 +1,42 @@ package dbixcsl_mssql_extra_tests; +use strict; +use warnings; use Test::More; use Test::Exception; -my $vendor = 'mssql'; - -sub vendor { - shift; - $vendor = shift; -} - # for cleanup in END -my $saved_dbh; +my $storage; sub extra { +{ create => [ - qq{ - CREATE TABLE [${vendor}_loader_test1.dot] ( + q{ + CREATE TABLE [mssql_loader_test1.dot] ( id INT IDENTITY NOT NULL PRIMARY KEY, dat VARCHAR(8) ) }, - qq{ - CREATE TABLE ${vendor}_loader_test2 ( - id INT IDENTITY NOT NULL PRIMARY KEY, - dat VARCHAR(100) DEFAULT 'foo', - num NUMERIC DEFAULT 10.89, - anint INT DEFAULT 6, - ts DATETIME DEFAULT getdate() - ) - }, - qq{ - CREATE TABLE ${vendor}_loader_test3 ( + q{ + CREATE TABLE mssql_loader_test3 ( id INT IDENTITY NOT NULL PRIMARY KEY ) }, - qq{ - CREATE VIEW ${vendor}_loader_test4 AS - SELECT * FROM ${vendor}_loader_test3 + q{ + CREATE VIEW mssql_loader_test4 AS + SELECT * FROM mssql_loader_test3 }, ], drop => [ - "[${vendor}_loader_test1.dot]", - "${vendor}_loader_test2", - "${vendor}_loader_test3" + "[mssql_loader_test1.dot]", + "mssql_loader_test3" ], - count => 15, + count => 8, run => sub { my ($schema, $monikers, $classes) = @_; # Test that the table above (with '.' in name) gets loaded correctly. - my $vendor_titlecased = "\u\L$vendor"; - ok((my $rs = eval { - $schema->resultset("${vendor_titlecased}LoaderTest1Dot") }), + $schema->resultset($monikers->{'[mssql_loader_test1.dot]'}) }), 'got a resultset for table with dot in name'); ok((my $from = eval { $rs->result_source->from }), @@ -61,39 +44,12 @@ sub extra { +{ is ref($from), 'SCALAR', '->table with dot in name is a scalar ref'; - is eval { $$from }, "[${vendor}_loader_test1.dot]", + is eval { $$from }, "[mssql_loader_test1.dot]", '->table with dot in name has correct name'; -# Test that column defaults are set correctly - ok(($rs = eval { - $schema->resultset("${vendor_titlecased}LoaderTest2") }), - 'got a resultset for table with column with default value'); - - my $rsrc = $rs->result_source; - - is eval { $rsrc->column_info('dat')->{default_value} }, 'foo', - 'correct default_value for column with literal string default'; - - is eval { $rsrc->column_info('anint')->{default_value} }, 6, - 'correct default_value for column with literal integer default'; - - cmp_ok eval { $rsrc->column_info('num')->{default_value} }, - '==', 10.89, - 'correct default_value for column with literal numeric default'; - - ok((my $function_default = - eval { $rsrc->column_info('ts')->{default_value} }), - 'got default_value for column with function default'); - - is ref($function_default), 'SCALAR', - 'default_value for function default is a SCALAR ref'; - - is eval { $$function_default }, 'getdate()', - 'default_value for function default is correct'; - # Test that identity columns do not have 'identity' in the data_type, and do # have is_auto_increment. - my $identity_col_info = $schema->resultset('LoaderTest10') + my $identity_col_info = $schema->resultset($monikers->{loader_test10}) ->result_source->column_info('id10'); is $identity_col_info->{data_type}, 'int', @@ -103,31 +59,35 @@ sub extra { +{ q{'INT IDENTITY' column has is_auto_increment => 1}; # Test that a bad view (where underlying table is gone) is ignored. - $saved_dbh = $schema->storage->dbh; - $saved_dbh->do("DROP TABLE ${vendor}_loader_test3"); + $storage = $schema->storage; + + my $dbh = $storage->dbh; + $dbh->do("DROP TABLE mssql_loader_test3"); my @warnings; { local $SIG{__WARN__} = sub { push @warnings, $_[0] }; $schema->rescan; } - ok ((grep /^Bad table or view '${vendor}_loader_test4'/, @warnings), + ok ((grep /^Bad table or view 'mssql_loader_test4'/, @warnings), 'bad view ignored'); throws_ok { - $schema->resultset("${vendor_titlecased}LoaderTest4") + $schema->resultset($monikers->{mssql_loader_test4}) } qr/Can't find source/, 'no source registered for bad view'; }, }} -# Clean up the bad view, table will be cleaned up in drops +# Clean up the bad view END { local $@; eval { - $saved_dbh->do($_) for ( -"CREATE TABLE ${vendor}_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)", -"DROP VIEW ${vendor}_loader_test4" + my $dbh = $storage->dbh; + $dbh->do($_) for ( +"CREATE TABLE mssql_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)", +"DROP VIEW mssql_loader_test4", +"DROP TABLE mssql_loader_test3", ); }; }