X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F13schema.t;h=3d382087efe2cf9a303218350dc417bdbebe62cb;hb=807290c3b024e14b17cb77a6d4d0c30f93856bae;hp=c85c3b6fb5730c054790d56e938c542cd05b8034;hpb=860d3652c5d400f2fe4984a8b1aaf21c59269927;p=dbsrgits%2FSQL-Translator.git diff --git a/t/13schema.t b/t/13schema.t index c85c3b6..3d38208 100644 --- a/t/13schema.t +++ b/t/13schema.t @@ -4,7 +4,8 @@ $| = 1; use strict; -use Test::More tests => 238; +use Test::More tests => 245; +use Test::Exception; use SQL::Translator::Schema::Constants; require_ok( 'SQL::Translator' ); @@ -715,3 +716,31 @@ require_ok( 'SQL::Translator::Schema' ); $s->add_procedure($p); } + +# +# Test field order +# +{ + my $s = SQL::Translator::Schema->new; + my $t = $s->add_table( name => 'person' ); + my $f3 = $t->add_field( name => 'age', order => 3 ); + my $f1 = $t->add_field( name => 'person_id', order => 1 ); + my $f2 = $t->add_field( name => 'name', order => 2 ); + my $f4 = $t->add_field( name => 'gender' ); + my $f5 = $t->add_field( name => 'alias' ); + + is( $f1->order, 1, 'Field order is passed, order is 1' ); + is( $f2->order, 2, 'Field order is passed, order is 2' ); + is( $f3->order, 3, 'Field order is passed, order is 3' ); + is( $f4->order, 4, 'Field order is not passed, order is 4' ); + is( $f5->order, 5, 'Field order is not passed, order is 5' ); + + my $t2 = $s->add_table( name => 'place' ); + $f2 = $t2->add_field( name => 'name', order => 2 ); + + throws_ok { my $f22 = $t2->add_field( name => 'name2', order => 2 ) } + qr/\QRequested order '2' for column 'name2' conflicts with already existing column 'name'/; + + throws_ok { $f1 = $t2->add_field( name => 'location' ) } + qr/field order incomplete/; +}