X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F13schema.t;h=0d69f9bfe902ce181bce6dcb06ef6d7cb10998fc;hb=2e11379ef0451e54acca5dee655b0c33272008ed;hp=7b596d7cca6ba67cfc977f5bd81c72328960795c;hpb=14f8758f3976b5c4982cd2b4ad462c5aaca87dc9;p=dbsrgits%2FSQL-Translator.git diff --git a/t/13schema.t b/t/13schema.t index 7b596d7..0d69f9b 100644 --- a/t/13schema.t +++ b/t/13schema.t @@ -4,7 +4,7 @@ $| = 1; use strict; -use Test::More 'no_plan'; # plans => 1; +use Test::More tests => 160; use SQL::Translator::Schema::Constants; require_ok( 'SQL::Translator::Schema' ); @@ -51,7 +51,8 @@ require_ok( 'SQL::Translator::Schema' ); my $redundant_table = $schema->add_table(name => 'foo'); is( $redundant_table, undef, qq[Can't create another "foo" table...] ); - like( $schema->error, qr/can't use table name/i, '... because "foo" exists' ); + like( $schema->error, qr/can't use table name/i, + '... because "foo" exists' ); # # Table default new @@ -63,12 +64,21 @@ require_ok( 'SQL::Translator::Schema' ); is( scalar @{ $fields || [] }, 0, 'Table "foo" has no fields' ); like( $foo_table->error, qr/no fields/i, 'Error for no fields' ); + is( $foo_table->comments, undef, 'No comments' ); + # # New table with args # - my $person_table = $schema->add_table( name => 'person' ); + my $person_table = $schema->add_table( + name => 'person', + comments => 'foo', + ); is( $person_table->name, 'person', 'Table name is "person"' ); is( $person_table->is_valid, undef, 'Table is not yet valid' ); + is( $person_table->comments, 'foo', 'Comments = "foo"' ); + is( join(',', $person_table->comments('bar')), 'foo,bar', + 'Table comments = "foo,bar"' ); + is( $person_table->comments, "foo\nbar", 'Table comments = "foo,bar"' ); # # Field default new @@ -82,16 +92,23 @@ require_ok( 'SQL::Translator::Schema' ); is( $f1->is_primary_key, '0', 'Field is_primary_key is false' ); is( $f1->is_nullable, 1, 'Field can be NULL' ); is( $f1->default_value, undef, 'Field default is undefined' ); + is( $f1->comments, '', 'No comments' ); - my $f2 = SQL::Translator::Schema::Field->new (name => 'f2') or - warn SQL::Translator::Schema::Field->error; + my $f2 = SQL::Translator::Schema::Field->new ( + name => 'f2', + comments => 'foo', + ) or warn SQL::Translator::Schema::Field->error; $f2 = $person_table->add_field( $f2 ); isa_ok( $f1, 'SQL::Translator::Schema::Field', 'f2' ); is( $f2->name, 'f2', 'Add field "f2"' ); is( $f2->is_nullable(0), 0, 'Field cannot be NULL' ); is( $f2->is_nullable(''), 0, 'Field cannot be NULL' ); is( $f2->is_nullable('0'), 0, 'Field cannot be NULL' ); - is( $f1->default_value(''), '', 'Field default is empty string' ); + is( $f2->default_value(''), '', 'Field default is empty string' ); + is( $f2->comments, 'foo', 'Field comment = "foo"' ); + is( join(',', $f2->comments('bar')), 'foo,bar', + 'Field comment = "foo,bar"' ); + is( $f2->comments, "foo\nbar", 'Field comment = "foo,bar"' ); $person_table = $f2->table( $person_table ); isa_ok( $person_table, 'SQL::Translator::Schema::Table', 'person_table' ); @@ -119,6 +136,12 @@ require_ok( 'SQL::Translator::Schema' ); is( $f1->size('30'), '30', 'Field size is "30"' ); is( $f1->is_primary_key(0), '0', 'Field is_primary_key is negative' ); + $f1->extra( foo => 'bar' ); + $f1->extra( { baz => 'quux' } ); + my %extra = $f1->extra; + is( $extra{'foo'}, 'bar', 'Field extra "foo" is "bar"' ); + is( $extra{'baz'}, 'quux', 'Field extra "baz" is "quux"' ); + # # New field with args # @@ -219,8 +242,17 @@ require_ok( 'SQL::Translator::Schema' ); isa_ok( $constraint2, 'SQL::Translator::Schema::Constraint', 'Constraint' ); is( $constraint2->name, 'bar', 'Constraint name is "bar"' ); + my $constraint3 = $person_table->add_constraint( + type => 'check', + expression => 'foo bar', + ) or die $person_table->error; + isa_ok( $constraint3, 'SQL::Translator::Schema::Constraint', 'Constraint' ); + is( $constraint3->type, CHECK_C, 'Constraint type is "CHECK"' ); + is( $constraint3->expression, 'foo bar', + 'Constraint expression is "foo bar"' ); + my $constraints = $person_table->get_constraints; - is( scalar @$constraints, 2, 'Two constraints' ); + is( scalar @$constraints, 3, 'Three constraints' ); is( $constraints->[0]->name, 'foo', '"foo" constraint' ); is( $constraints->[1]->name, 'bar', '"bar" constraint' ); @@ -370,7 +402,6 @@ require_ok( 'SQL::Translator::Schema' ); my $t = $s->add_table( name => 'person' ); is( $t->primary_key, undef, 'No primary key' ); - like( $t->error, qr/no primary key/i, 'No primary key error' ); is( $t->primary_key('person_id'), undef, q[Can't make PK on "person_id"...] );