add is_deferrable => 1 to belongs_to by default
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 12pg_common.t
index bf1775c..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,17 +85,25 @@ my $tester = dbixcsl_common_tests->new(
             q{
                 COMMENT ON COLUMN pg_loader_test1.value IS 'The Column'
             },
-            # Test to make sure data_types that don't need a size => don't
-            # have one.
             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_test3 (
+                    id SERIAL NOT NULL PRIMARY KEY,
                     a_bigint BIGINT,
                     an_int8 INT8,
                     a_bigserial BIGSERIAL,
                     a_serial8 SERIAL8,
                     a_bit BIT,
-                    a_bit_varying_with_precision BIT VARYING(8),
                     a_boolean BOOLEAN,
                     a_bool BOOL,
                     a_box BOX,
@@ -79,12 +144,20 @@ my $tester = dbixcsl_common_tests->new(
                     a_timestamp_without_time_zone TIMESTAMP WITHOUT TIME ZONE,
                     a_timestamp_without_time_zone_with_precision TIMESTAMP(2) WITHOUT TIME ZONE,
                     a_timestamp_with_time_zone TIMESTAMP WITH TIME ZONE,
-                    a_timestamp_with_time_zone_with_precision TIMESTAMP(2) WITH TIME ZONE
+                    a_timestamp_with_time_zone_with_precision TIMESTAMP(2) WITH TIME ZONE,
+                    a_bit_varying_with_precision BIT VARYING(2),
+                    a_varbit_with_precision VARBIT(2),
+                    a_character_varying_with_precision CHARACTER VARYING(2),
+                    a_varchar_with_precision VARCHAR(2),
+                    a_character_with_precision CHARACTER(2),
+                    a_char_with_precision CHAR(2),
+                    the_numeric NUMERIC(6, 3),
+                    the_decimal DECIMAL(6, 3)
                 )
             },
         ],
-        drop  => [ qw/ pg_loader_test1 pg_loader_test2 / ],
-        count => 49,
+        drop  => [ qw/ pg_loader_test1 pg_loader_test2 pg_loader_test3 / ],
+        count => 57,
         run   => sub {
             my ($schema, $monikers, $classes) = @_;
 
@@ -102,8 +175,20 @@ 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;
-            my @type_columns = grep !/^id\z/, $rsrc->columns;
+            $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;
             my %with_precision;
@@ -118,16 +203,24 @@ 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) {
                 my ($data_type) = $col =~ /^an?_(.*)_with_precision\z/;
                 ($data_type = uc $data_type) =~ s/_/ /g;
+                my $size = $rsrc->column_info($col)->{size};
 
-                ok($rsrc->column_info($col)->{size},
-                    "$data_type with precision has a 'size' column_info");
+                is $size, 2,
+                  "$data_type with precision has a correct 'size' column_info";
             }
+
+            is_deeply $rsrc->column_info('the_numeric')->{size}, [6,3],
+                'size for NUMERIC(precision, scale) is correct';
+
+            is_deeply $rsrc->column_info('the_decimal')->{size}, [6,3],
+                'size for DECIMAL(precision, scale) is correct';
         },
     },
 );