[Bast-commits] r3436 - branches/DBIx-Class-current/t

blblack at dev.catalyst.perl.org blblack at dev.catalyst.perl.org
Tue May 29 20:20:57 GMT 2007


Author: blblack
Date: 2007-05-29 20:20:56 +0100 (Tue, 29 May 2007)
New Revision: 3436

Modified:
   branches/DBIx-Class-current/t/71mysql.t
   branches/DBIx-Class-current/t/72pg.t
   branches/DBIx-Class-current/t/73oracle.t
   branches/DBIx-Class-current/t/745db2.t
   branches/DBIx-Class-current/t/746db2_400.t
   branches/DBIx-Class-current/t/74mssql.t
   branches/DBIx-Class-current/t/93nobindvars.t
Log:
converted the vendor tests to use schema objects intead of schema classes
also moved some of the final "DROP TABLE" stuff into END blocks to drop them more reliably

Modified: branches/DBIx-Class-current/t/71mysql.t
===================================================================
--- branches/DBIx-Class-current/t/71mysql.t	2007-05-29 19:08:33 UTC (rev 3435)
+++ branches/DBIx-Class-current/t/71mysql.t	2007-05-29 19:20:56 UTC (rev 3436)
@@ -15,9 +15,9 @@
 
 plan tests => 5;
 
-DBICTest::Schema->compose_namespace('MySQLTest' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
 
-my $dbh = MySQLTest->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
 
 $dbh->do("DROP TABLE IF EXISTS artist;");
 
@@ -25,17 +25,18 @@
 
 #'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
 
-MySQLTest::Artist->load_components('PK::Auto');
+# This is in Core now, but it's here just to test that it doesn't break
+$schema->class('Artist')->load_components('PK::Auto');
 
 # test primary key handling
-my $new = MySQLTest::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
 ok($new->artistid, "Auto-PK worked");
 
 # test LIMIT support
 for (1..6) {
-    MySQLTest::Artist->create({ name => 'Artist ' . $_ });
+    $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
 }
-my $it = MySQLTest::Artist->search( {},
+my $it = $schema->resultset('Artist')->search( {},
     { rows => 3,
       offset => 2,
       order_by => 'artistid' }
@@ -80,9 +81,11 @@
         $test_type_info->{charfield}->{data_type} = 'VARCHAR';
     }
 
-    my $type_info = MySQLTest->schema->storage->columns_info_for('artist');
+    my $type_info = $schema->storage->columns_info_for('artist');
     is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
 }
 
 # clean up our mess
-$dbh->do("DROP TABLE artist");
+END {
+    $dbh->do("DROP TABLE artist") if $dbh;
+}

Modified: branches/DBIx-Class-current/t/72pg.t
===================================================================
--- branches/DBIx-Class-current/t/72pg.t	2007-05-29 19:08:33 UTC (rev 3435)
+++ branches/DBIx-Class-current/t/72pg.t	2007-05-29 19:20:56 UTC (rev 3436)
@@ -12,7 +12,7 @@
   use warnings;
   use base 'DBIx::Class';
 
-  __PACKAGE__->load_components(qw/PK::Auto Core/);
+  __PACKAGE__->load_components(qw/Core/);
   __PACKAGE__->table('casecheck');
   __PACKAGE__->add_columns(qw/id name NAME uc_name/);
   __PACKAGE__->column_info_from_storage(1);
@@ -30,21 +30,22 @@
 plan tests => 8;
 
 DBICTest::Schema->load_classes( 'Casecheck' );
-DBICTest::Schema->compose_namespace('PgTest' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
 
-my $dbh = PgTest->schema->storage->dbh;
-PgTest->schema->source("Artist")->name("testschema.artist");
+my $dbh = $schema->storage->dbh;
+$schema->source("Artist")->name("testschema.artist");
 $dbh->do("CREATE SCHEMA testschema;");
 $dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));");
 ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table');
 
-PgTest::Artist->load_components('PK::Auto');
+# This is in Core now, but it's here just to test that it doesn't break
+$schema->class('Artist')->load_components('PK::Auto');
 
-my $new = PgTest::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
 
 is($new->artistid, 1, "Auto-PK worked");
 
-$new = PgTest::Artist->create({ name => 'bar' });
+$new = $schema->resultset('Artist')->create({ name => 'bar' });
 
 is($new->artistid, 2, "Auto-PK worked");
 
@@ -69,7 +70,7 @@
 };
 
 
-my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist');
+my $type_info = $schema->storage->columns_info_for('testschema.artist');
 my $artistid_defval = delete $type_info->{artistid}->{default_value};
 like($artistid_defval,
      qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
@@ -77,16 +78,20 @@
 is_deeply($type_info, $test_type_info,
           'columns_info_for - column data types');
 
-my $name_info = PgTest::Casecheck->column_info( 'name' );
+my $name_info = $schema->source('Casecheck')->column_info( 'name' );
 is( $name_info->{size}, 1, "Case sensitive matching info for 'name'" );
 
-my $NAME_info = PgTest::Casecheck->column_info( 'NAME' );
+my $NAME_info = $schema->source('Casecheck')->column_info( 'NAME' );
 is( $NAME_info->{size}, 2, "Case sensitive matching info for 'NAME'" );
 
-my $uc_name_info = PgTest::Casecheck->column_info( 'uc_name' );
+my $uc_name_info = $schema->source('Casecheck')->column_info( 'uc_name' );
 is( $uc_name_info->{size}, 3, "Case insensitive matching info for 'uc_name'" );
 
-$dbh->do("DROP TABLE testschema.artist;");
-$dbh->do("DROP TABLE testschema.casecheck;");
-$dbh->do("DROP SCHEMA testschema;");
+END {
+    if($dbh) {
+        $dbh->do("DROP TABLE testschema.artist;");
+        $dbh->do("DROP TABLE testschema.casecheck;");
+        $dbh->do("DROP SCHEMA testschema;");
+    }
+}
 

Modified: branches/DBIx-Class-current/t/73oracle.t
===================================================================
--- branches/DBIx-Class-current/t/73oracle.t	2007-05-29 19:08:33 UTC (rev 3435)
+++ branches/DBIx-Class-current/t/73oracle.t	2007-05-29 19:20:56 UTC (rev 3436)
@@ -13,9 +13,9 @@
 
 plan tests => 6;
 
-DBICTest::Schema->compose_namespace('OraTest' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
 
-my $dbh = OraTest->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
 
 eval {
   $dbh->do("DROP SEQUENCE artist_seq");
@@ -42,18 +42,20 @@
   END;
 });
 
-OraTest::Artist->load_components('PK::Auto');
-OraTest::CD->load_components('PK::Auto::Oracle');
-OraTest::Track->load_components('PK::Auto::Oracle');
+# This is in Core now, but it's here just to test that it doesn't break
+$schema->class('Artist')->load_components('PK::Auto');
+# These are compat shims for PK::Auto...
+$schema->class('CD')->load_components('PK::Auto::Oracle');
+$schema->class('Track')->load_components('PK::Auto::Oracle');
 
 # test primary key handling
-my $new = OraTest::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
 is($new->artistid, 1, "Oracle Auto-PK worked");
 
 # test join with row count ambiguity
-my $cd = OraTest::CD->create({ cdid => 1, artist => 1, title => 'EP C', year => '2003' });
-my $track = OraTest::Track->create({ trackid => 1, cd => 1, position => 1, title => 'Track1' });
-my $tjoin = OraTest::Track->search({ 'me.title' => 'Track1'},
+my $cd = $schema->resultset('CD')->create({ cdid => 1, artist => 1, title => 'EP C', year => '2003' });
+my $track = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1' });
+my $tjoin = $schema->resultset('Track')->search({ 'me.title' => 'Track1'},
         { join => 'cd',
           rows => 2 }
 );
@@ -61,8 +63,8 @@
 is($tjoin->next->title, 'Track1', "ambiguous column ok");
 
 # check count distinct with multiple columns
-my $other_track = OraTest::Track->create({ trackid => 2, cd => 1, position => 1, title => 'Track2' });
-my $tcount = OraTest::Track->search(
+my $other_track = $schema->resultset('Track')->create({ trackid => 2, cd => 1, position => 1, title => 'Track2' });
+my $tcount = $schema->resultset('Track')->search(
     {},
     {
         select => [{count => {distinct => ['position', 'title']}}],
@@ -74,9 +76,9 @@
 
 # test LIMIT support
 for (1..6) {
-    OraTest::Artist->create({ name => 'Artist ' . $_ });
+    $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
 }
-my $it = OraTest::Artist->search( {},
+my $it = $schema->resultset('Artist')->search( {},
     { rows => 3,
       offset => 2,
       order_by => 'artistid' }
@@ -88,8 +90,12 @@
 is( $it->next, undef, "next past end of resultset ok" );
 
 # clean up our mess
-$dbh->do("DROP SEQUENCE artist_seq");
-$dbh->do("DROP TABLE artist");
-$dbh->do("DROP TABLE cd");
-$dbh->do("DROP TABLE track");
+END {
+    if($dbh) {
+        $dbh->do("DROP SEQUENCE artist_seq");
+        $dbh->do("DROP TABLE artist");
+        $dbh->do("DROP TABLE cd");
+        $dbh->do("DROP TABLE track");
+    }
+}
 

Modified: branches/DBIx-Class-current/t/745db2.t
===================================================================
--- branches/DBIx-Class-current/t/745db2.t	2007-05-29 19:08:33 UTC (rev 3435)
+++ branches/DBIx-Class-current/t/745db2.t	2007-05-29 19:20:56 UTC (rev 3436)
@@ -14,27 +14,26 @@
 
 plan tests => 6;
 
-DBICTest::Schema->compose_namespace('DB2Test' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
 
-my $dbh = DB2Test->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
 
 $dbh->do("DROP TABLE artist", { RaiseError => 0, PrintError => 0 });
 
 $dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10));");
 
-#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
+# This is in core, just testing that it still loads ok
+$schema->class('Artist')->load_components('PK::Auto');
 
-DB2Test::Artist->load_components('PK::Auto');
-
 # test primary key handling
-my $new = DB2Test::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
 ok($new->artistid, "Auto-PK worked");
 
 # test LIMIT support
 for (1..6) {
-    DB2Test::Artist->create({ name => 'Artist ' . $_ });
+    $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
 }
-my $it = DB2Test::Artist->search( {},
+my $it = $schema->resultset('Artist')->search( {},
     { rows => 3,
       order_by => 'artistid'
       }
@@ -64,11 +63,10 @@
 };
 
 
-my $type_info = DB2Test->schema->storage->columns_info_for('artist');
+my $type_info = $schema->storage->columns_info_for('artist');
 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
 
-
-
 # clean up our mess
-$dbh->do("DROP TABLE artist");
-
+END {
+    $dbh->do("DROP TABLE artist") if $dbh;
+}

Modified: branches/DBIx-Class-current/t/746db2_400.t
===================================================================
--- branches/DBIx-Class-current/t/746db2_400.t	2007-05-29 19:08:33 UTC (rev 3435)
+++ branches/DBIx-Class-current/t/746db2_400.t	2007-05-29 19:20:56 UTC (rev 3436)
@@ -17,25 +17,26 @@
 
 plan tests => 6;
 
-DBICTest::Schema->compose_namespace('DB2Test' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
 
-my $dbh = DB2Test->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
 
 $dbh->do("DROP TABLE artist", { RaiseError => 0, PrintError => 0 });
 
 $dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10))");
 
-DB2Test::Artist->load_components('PK::Auto');
+# Just to test loading, already in Core
+$schema->class('Artist')->load_components('PK::Auto');
 
 # test primary key handling
-my $new = DB2Test::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
 ok($new->artistid, "Auto-PK worked");
 
 # test LIMIT support
 for (1..6) {
-    DB2Test::Artist->create({ name => 'Artist ' . $_ });
+    $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
 }
-my $it = DB2Test::Artist->search( {},
+my $it = $schema->resultset('Artist')->search( {},
     { rows => 3,
       order_by => 'artistid'
       }
@@ -65,11 +66,11 @@
 };
 
 
-my $type_info = DB2Test->schema->storage->columns_info_for('artist');
+my $type_info = $schema->storage->columns_info_for('artist');
 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
 
-
-
 # clean up our mess
-$dbh->do("DROP TABLE artist");
+END {
+    $dbh->do("DROP TABLE artist") if $dbh;
+}
 

Modified: branches/DBIx-Class-current/t/74mssql.t
===================================================================
--- branches/DBIx-Class-current/t/74mssql.t	2007-05-29 19:08:33 UTC (rev 3435)
+++ branches/DBIx-Class-current/t/74mssql.t	2007-05-29 19:20:56 UTC (rev 3436)
@@ -18,28 +18,30 @@
 $storage_type = '::DBI::Sybase::MSSQL' if $dsn =~ /^dbi:Sybase:/;
 # Add more for others in the future when they exist (ODBC? ADO? JDBC?)
 
-DBICTest::Schema->storage_type($storage_type);
-DBICTest::Schema->compose_namespace( 'MSSQLTest' => $dsn, $user, $pass );
+my $schema = DBICTest::Schema->clone;
+$schema->storage_type($storage_type);
+$schema->connection($dsn, $user, $pass);
 
-my $dbh = MSSQLTest->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
 
 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
     DROP TABLE artist");
 
 $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(255));");
 
-MSSQLTest::Artist->load_components('PK::Auto::MSSQL');
+# Just to test compat shim, Auto is in Core
+$schema->class('Artist')->load_components('PK::Auto::MSSQL');
 
 # Test PK
-my $new = MSSQLTest::Artist->create( { name => 'foo' } );
+my $new = $schema->resultset('Artist')->create( { name => 'foo' } );
 ok($new->artistid, "Auto-PK worked");
 
 # Test LIMIT
 for (1..6) {
-    MSSQLTest::Artist->create( { name => 'Artist ' . $_ } );
+    $schema->resultset('Artist')->create( { name => 'Artist ' . $_ } );
 }
 
-my $it = MSSQLTest::Artist->search( { },
+my $it = $schema->resultset('Artist')->search( { },
     { rows     => 3,
       offset   => 2,
       order_by => 'artistid'
@@ -52,3 +54,8 @@
 $it->next;
 is( $it->next, undef, "next past end of resultset ok" );
 
+# clean up our mess
+END {
+    $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist")
+        if $dbh;
+}

Modified: branches/DBIx-Class-current/t/93nobindvars.t
===================================================================
--- branches/DBIx-Class-current/t/93nobindvars.t	2007-05-29 19:08:33 UTC (rev 3435)
+++ branches/DBIx-Class-current/t/93nobindvars.t	2007-05-29 19:20:56 UTC (rev 3436)
@@ -28,29 +28,27 @@
     $INC{'DBIx/Class/Storage/DBI/MySQLNoBindVars.pm'} = 1;
 }
 
-DBICTest::Schema->storage(undef); # just in case?
-DBICTest::Schema->storage_type('::DBI::MySQLNoBindVars');
-DBICTest::Schema->compose_namespace('MySQLTest' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->clone;
+$schema->storage_type('::DBI::MySQLNoBindVars');
+$schema->connection($dsn, $user, $pass);
 
-my $dbh = MySQLTest->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
 
 $dbh->do("DROP TABLE IF EXISTS artist;");
 
 $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));");
 
-#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
+$schema->class('Artist')->load_components('PK::Auto');
 
-MySQLTest::Artist->load_components('PK::Auto');
-
 # test primary key handling
-my $new = MySQLTest::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
 ok($new->artistid, "Auto-PK worked");
 
 # test LIMIT support
 for (1..6) {
-    MySQLTest::Artist->create({ name => 'Artist ' . $_ });
+    $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
 }
-my $it = MySQLTest::Artist->search( {},
+my $it = $schema->resultset('Artist')->search( {},
     { rows => 3,
       offset => 2,
       order_by => 'artistid' }
@@ -62,4 +60,6 @@
 is( $it->next, undef, "next past end of resultset ok" );
 
 # clean up our mess
-$dbh->do("DROP TABLE artist");
+END {
+    $dbh->do("DROP TABLE artist");
+}




More information about the Bast-commits mailing list