add is_deferrable => 1 to belongs_to by default
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 12pg_common.t
index 109bb33..b10dfa6 100644 (file)
@@ -11,9 +11,66 @@ my $password = $ENV{DBICTEST_PG_PASS} || '';
 my $tester = dbixcsl_common_tests->new(
     vendor      => 'Pg',
     auto_inc_pk => 'SERIAL NOT NULL PRIMARY KEY',
+    default_function => 'now()',
     dsn         => $dsn,
     user        => $user,
     password    => $password,
+    data_types  => {
+       'bigint'    => { size => undef, data_type => 'bigint' },
+       'int8'      => { size => undef, data_type => 'int8' },
+       'bigserial' => { size => undef, data_type => 'bigserial' },
+       'serial8'   => { size => undef, data_type => 'serial8' },
+       'bit'       => { size => undef, data_type => 'bit' },
+       'boolean'   => { size => undef, data_type => 'boolean' },
+       'bool'      => { size => undef, data_type => 'bool' },
+       'box'       => { size => undef, data_type => 'box' },
+       'bytea'     => { size => undef, data_type => 'bytea' },
+       'cidr'      => { size => undef, data_type => 'cidr' },
+       'circle'    => { size => undef, data_type => 'circle' },
+       'date'      => { size => undef, data_type => 'date' },
+       'double precision' => { size => undef, data_type => 'double precision' },
+       'float8'      => { size => undef, data_type => 'float8' },
+       'inet'        => { size => undef, data_type => 'inet' },
+       'integer'     => { size => undef, data_type => 'integer' },
+       'int'         => { size => undef, data_type => 'int' },
+       'int4'        => { size => undef, data_type => 'int4' },
+       'interval'    => { size => undef, data_type => 'interval' },
+       'interval(2)' => { size => 2, data_type => 'interval' },
+       'line'        => { size => undef, data_type => 'line' },
+       'lseg'        => { size => undef, data_type => 'lseg' },
+       'macaddr'     => { size => undef, data_type => 'macaddr' },
+       'money'       => { size => undef, data_type => 'money' },
+       'path'        => { size => undef, data_type => 'path' },
+       'point'       => { size => undef, data_type => 'point' },
+       'polygon'     => { size => undef, data_type => 'polygon' },
+       'real'        => { size => undef, data_type => 'real' },
+       'float4'      => { size => undef, data_type => 'float4' },
+       'smallint'    => { size => undef, data_type => 'smallint' },
+       'int2'        => { size => undef, data_type => 'int2' },
+       'serial'      => { size => undef, data_type => 'serial' },
+       'serial4'     => { size => undef, data_type => 'serial4' },
+       'text'        => { size => undef, data_type => 'text' },
+       'time'        => { size => undef, data_type => 'time' },
+       'time(2)'     => { size => 2, data_type => 'time' },
+       'time without time zone'         => { size => undef, data_type => 'time without time zone' },
+       'time(2) without time zone'      => { size => 2, data_type => 'time without time zone' },
+       'time with time zone'            => { size => undef, data_type => 'time with time zone' },
+       'time(2) with time zone'         => { size => 2, data_type => 'time with time zone' },
+       'timestamp'                      => { size => undef, data_type => 'timestamp' },
+       'timestamp(2)'                   => { size => 2, data_type => 'timestamp' },
+       'timestamp without time zone'    => { size => undef, data_type => 'timestamp without time zone' },
+       'timestamp(2) without time zone' => { size => 2, data_type => 'timestamp without time zone' },
+       'timestamp with time zone'       => { size => undef, data_type => 'timestamp with time zone' },
+       'timestamp(2) with time zone'    => { size => 2, data_type => 'timestamp with time zone' },
+       'bit varying(2)'                 => { size => 2, data_type => 'bit varying' },
+       'varbit(2)'                      => { size => 2, data_type => 'varbit' },
+       'character varying(2)'           => { size => 2, data_type => 'character varying' },
+       'varchar(2)'                     => { size => 2, data_type => 'varchar' },
+       'character(2)'                   => { size => 2, data_type => 'character' },
+       'char(2)'                        => { size => 2, data_type => 'char' },
+       'numeric(6, 3)'                  => { size => [6,3], data_type => 'numeric' },
+       'decimal(6, 3)'                  => { size => [6,3], data_type => 'decimal' },
+    },
     extra       => {
         create => [
             q{
@@ -28,10 +85,19 @@ my $tester = dbixcsl_common_tests->new(
             q{
                 COMMENT ON COLUMN pg_loader_test1.value IS 'The Column'
             },
+            q{
+                CREATE TABLE pg_loader_test2 (
+                    id SERIAL NOT NULL PRIMARY KEY,
+                    value VARCHAR(100)
+                )
+            },
+            q{
+                COMMENT ON TABLE pg_loader_test2 IS 'very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long comment'
+            },
             # Test to make sure data_types that don't need a size => don't
             # have one and check varying types have the correct size.
             q{
-                CREATE TABLE pg_loader_test2 (
+                CREATE TABLE pg_loader_test3 (
                     id SERIAL NOT NULL PRIMARY KEY,
                     a_bigint BIGINT,
                     an_int8 INT8,
@@ -89,11 +155,9 @@ my $tester = dbixcsl_common_tests->new(
                     the_decimal DECIMAL(6, 3)
                 )
             },
-# XXX figure out what to do with DECIMAL(precision, scale) aka
-# NUMERIC(precision, scale)
         ],
-        drop  => [ qw/ pg_loader_test1 pg_loader_test2 / ],
-        count => 56,
+        drop  => [ qw/ pg_loader_test1 pg_loader_test2 pg_loader_test3 / ],
+        count => 57,
         run   => sub {
             my ($schema, $monikers, $classes) = @_;
 
@@ -111,7 +175,19 @@ my $tester = dbixcsl_common_tests->new(
             like $code, qr/^=head2 value\n\n(.+:.+\n)+\nThe Column\n\n/m,
                 'column comment and attrs';
 
-            my $rsrc = $schema->resultset('PgLoaderTest2')->result_source;
+            $class    = $classes->{pg_loader_test2};
+            $filename = $schema->_loader->_get_dump_filename($class);
+
+            $code = do {
+                local ($/, @ARGV) = (undef, $filename);
+                <>;
+            };
+
+            like $code, qr/^=head1 NAME\n\n^$class\n\n=head1 DESCRIPTION\n\n^very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long comment\n\n^=cut\n/m,
+                'long table comment is in DESCRIPTION';
+
+            my $rsrc = $schema->resultset($monikers->{pg_loader_test3})
+                ->result_source;
             my @type_columns = grep /^a/, $rsrc->columns;
             my @without_precision = grep !/_with_precision\z/, @type_columns;
             my @with_precision    = grep  /_with_precision\z/, @type_columns;
@@ -127,7 +203,8 @@ my $tester = dbixcsl_common_tests->new(
                 ok((not exists $rsrc->column_info($col)->{size}),
                     "$data_type " .
                     (exists $with_precision{$col} ? 'without precision ' : '') .
-                    "has no 'size' column_info");
+                    "has no 'size' column_info")
+                or diag "size is ".$rsrc->column_info($col)->{size}."\n";
             }
 
             for my $col (@with_precision) {