better money value comparison in tests
[dbsrgits/DBIx-Class.git] / t / 745db2.t
index 82d3c2c..3f635f8 100644 (file)
@@ -12,38 +12,49 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/};
 plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test'
   unless ($dsn && $user);
 
-plan tests => 6;
+plan tests => 9;
 
-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 });
+eval { $dbh->do("DROP TABLE artist") };
 
-$dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10));");
+$dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10), rank INTEGER DEFAULT 13);");
 
-#'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');
+my $ars = $schema->resultset('Artist');
 
 # test primary key handling
-my $new = DB2Test::Artist->create({ name => 'foo' });
+my $new = $ars->create({ name => 'foo' });
 ok($new->artistid, "Auto-PK worked");
 
-# test LIMIT support
+my $init_count = $ars->count;
 for (1..6) {
-    DB2Test::Artist->create({ name => 'Artist ' . $_ });
+    $ars->create({ name => 'Artist ' . $_ });
 }
-my $it = DB2Test::Artist->search( {},
-    { rows => 3,
-      order_by => 'artistid'
-      }
+is ($ars->count, $init_count + 6, 'Simple count works');
+
+# test LIMIT support
+my $it = $ars->search( {},
+  {
+    rows => 3,
+    order_by => 'artistid'
+  }
 );
 is( $it->count, 3, "LIMIT count ok" );
+
+my @all = $it->all;
+is (@all, 3, 'Number of ->all objects matches count');
+
+$it->reset;
 is( $it->next->name, "foo", "iterator->next ok" );
-$it->next;
+is( $it->next->name, "Artist 1", "iterator->next ok" );
 is( $it->next->name, "Artist 2", "iterator->next ok" );
-is( $it->next, undef, "next past end of resultset ok" );
+is( $it->next, undef, "next past end of resultset ok" );  # this can not succeed if @all > 3
+
 
 my $test_type_info = {
     'artistid' => {
@@ -61,14 +72,18 @@ my $test_type_info = {
         'is_nullable' => 1,
         'size' => 10 
     },
+    'rank' => {
+        'data_type' => 'INTEGER',
+        'is_nullable' => 1,
+        'size' => 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;
+}