added expected trigger and stored procedure output
[dbsrgits/SQL-Translator.git] / t / 13schema.t
index e72da02..f0f873e 100644 (file)
@@ -4,7 +4,7 @@
 $| = 1;
 
 use strict;
-use Test::More tests => 229;
+use Test::More tests => 238;
 use SQL::Translator::Schema::Constants;
 
 require_ok( 'SQL::Translator' );
@@ -584,13 +584,13 @@ require_ok( 'SQL::Translator::Schema' );
     $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;
@@ -601,8 +601,8 @@ 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( 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"] );
 
@@ -613,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
     #