Add a size/precision field to test file, make sure xml parser/producer work fine
[dbsrgits/SQL-Translator.git] / t / 16xml-parser.t
index 19c6111..ae96dd4 100644 (file)
@@ -27,7 +27,7 @@ use constant DEBUG => (exists $opt{d} ? 1 : 0);
 #=============================================================================
 
 BEGIN {
-    maybe_plan(204, 'SQL::Translator::Parser::XML::SQLFairy');
+    maybe_plan(224, 'SQL::Translator::Parser::XML::SQLFairy');
 }
 
 my $testschema = "$Bin/data/xml/schema.xml";
@@ -39,12 +39,21 @@ $sqlt = SQL::Translator->new(
     add_drop_table => 1,
 );
 die "Can't find test schema $testschema" unless -e $testschema;
-my $sql = $sqlt->translate(
+
+my $sql;
+{
+  my @w;
+  local $SIG{__WARN__} = sub { push @w, $_[0] if $_[0] =~ /The database_event tag is deprecated - please use database_events/ };
+
+  $sql = $sqlt->translate(
     from     => 'XML-SQLFairy',
     to       => 'MySQL',
     filename => $testschema,
-) or die $sqlt->error;
-print $sql if DEBUG;
+  ) or die $sqlt->error;
+  print $sql if DEBUG;
+
+  ok (@w, 'database_event deprecation warning issued');
+}
 
 # Test the schema objs generted from the XML
 #
@@ -90,7 +99,7 @@ schema_ok( $scma, {
                 {
                     name => "email",
                     data_type => "varchar",
-                    size => 255,
+                    size => 500,
                     is_unique => 1,
                     default_value => undef,
                     is_nullable => 1,
@@ -190,6 +199,12 @@ schema_ok( $scma, {
                     is_primary_key => 1,
                     is_auto_increment => 1,
                 },
+                {
+                    name => "num",
+                    data_type => "numeric",
+                    default_value => undef,
+                    size => '10,2',
+                },
             ],
         }, # end table Another
     ], # end tables
@@ -197,7 +212,7 @@ schema_ok( $scma, {
     views => [
         {
             name => 'email_list',
-            sql => "SELECT email FROM Basic WHERE email IS NOT NULL",
+            sql => "SELECT email FROM Basic WHERE (email IS NOT NULL)",
             fields => ['email'],
             extra => {
                 foo => "bar",
@@ -220,6 +235,16 @@ schema_ok( $scma, {
                 bar => "baz",
             },
         },
+        {
+            name                => 'bar_trigger',
+            perform_action_when => 'before',
+            database_events     => 'insert,update',
+            on_table            => 'Basic',
+            action              => 'update modified2=timestamp();',
+            extra => {
+                hello => "aliens",
+            },
+        },
     ],
 
     procedures => [