X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F13schema.t;h=f0f873e44563b77d9ba26ffb6bb5f41e3918ac37;hb=f8a4f3b4be568ed3148e7cf8b89939baea021a36;hp=ec08a022983573a499dcc9f7ddf52074eb1b8049;hpb=650f87eb1975f9fd8214abde49e383a960335b37;p=dbsrgits%2FSQL-Translator.git diff --git a/t/13schema.t b/t/13schema.t index ec08a02..f0f873e 100644 --- a/t/13schema.t +++ b/t/13schema.t @@ -4,7 +4,7 @@ $| = 1; use strict; -use Test::More tests => 232; +use Test::More tests => 238; use SQL::Translator::Schema::Constants; require_ok( 'SQL::Translator' ); @@ -411,19 +411,6 @@ require_ok( 'SQL::Translator::Schema' ); } # -# Graph -# -{ - my $tr = SQL::Translator->new( - parser => "PostgreSQL", - ); - - ok( $tr->translate('t/data/pgsql/wiki.sql'), 'Translate PG' ); - ok( my $schema = $tr->schema, 'Got Schema' ); - ok( my $graph = $schema->as_graph, 'Graph made'); -} - -# # Test ability to introspect some values # { @@ -431,7 +418,7 @@ require_ok( 'SQL::Translator::Schema' ); name => 'foo', database => 'PostgreSQL', ); - my $t = $s->add_table( name => 'person' ) or warn $s->erro; + my $t = $s->add_table( name => 'person' ) or warn $s->error; my $f = $t->add_field( name => 'person_id' ) or warn $t->error; $f->data_type('serial'); @@ -594,15 +581,16 @@ require_ok( 'SQL::Translator::Schema' ); # { my $s = SQL::Translator::Schema->new(name => 'TrigTest'); + $s->add_table(name=>'foo') or die "Couldn't create table: ", $s->error; my $name = 'foo_trigger'; my $perform_action_when = 'after'; - my $database_event = 'insert'; + my $database_events = 'insert'; my $on_table = 'foo'; my $action = 'update modified=timestamp();'; my $t = $s->add_trigger( name => $name, perform_action_when => $perform_action_when, - database_event => $database_event, + database_events => $database_events, on_table => $on_table, action => $action, ) or die $s->error; @@ -613,9 +601,9 @@ require_ok( 'SQL::Translator::Schema' ); is( $t->name, $name, qq[Name is "$name"] ); is( $t->perform_action_when, $perform_action_when, qq[Perform action when is "$perform_action_when"] ); - is( $t->database_event, $database_event, - qq[Database event is "$database_event"] ); - is( $t->on_table, $on_table, qq[Table is "$on_table"] ); + is( join(',', $t->database_events), $database_events, + qq[Database event is "$database_events"] ); + isa_ok( $t->table, 'SQL::Translator::Schema::Table', qq[table is a Table"] ); is( $t->action, $action, qq[Action is "$action"] ); my @triggs = $s->get_triggers; @@ -625,6 +613,46 @@ require_ok( 'SQL::Translator::Schema' ); isa_ok( $t1, 'SQL::Translator::Schema::Trigger', 'Trigger' ); is( $t1->name, $name, qq[Name is "$name"] ); + + + my $s2 = SQL::Translator::Schema->new(name => 'TrigTest2'); + $s2->add_table(name=>'foo') or die "Couldn't create table: ", $s2->error; + my $t2 = $s2->add_trigger( + name => 'foo_trigger', + perform_action_when => 'after', + database_events => [qw/insert update/], + on_table => 'foo', + action => 'update modified=timestamp();', + ) or die $s2->error; + isa_ok( $t2, 'SQL::Translator::Schema::Trigger', 'Trigger' ); + isa_ok( $t2->schema, 'SQL::Translator::Schema', 'Schema' ); + is( $t2->schema->name, 'TrigTest2', qq[Schema name is "'TrigTest2'"] ); + is( $t2->name, 'foo_trigger', qq[Name is "foo_trigger"] ); + is_deeply( + [$t2->database_events], + [qw/insert update/], + "Database events are [qw/insert update/] " + ); + isa_ok($t2->database_events,'ARRAY','Database events'); + + # + # Trigger equal tests + # + isnt( + $t1->equals($t2), + 1, + 'Compare two Triggers with database_event and database_events' + ); + + $t1->database_events($database_events); + $t2->database_events($database_events); + is($t1->equals($t2),1,'Compare two Triggers with database_event'); + + $t2->database_events(''); + $t1->database_events([qw/update insert/]); + $t2->database_events([qw/insert update/]); + is($t1->equals($t2),1,'Compare two Triggers with database_events'); + # # $schema-> drop_trigger #