test cleanups
[dbsrgits/DBIx-Class.git] / t / 99dbic_sqlt_parser.t
index d4b1a9f..313d2a6 100644 (file)
@@ -2,6 +2,7 @@
 use strict;
 use warnings;
 use Test::More;
+use Test::Exception;
 use lib qw(t/lib);
 use DBICTest;
 
@@ -15,7 +16,7 @@ BEGIN {
 my $schema = DBICTest->init_schema();
 # Dummy was yanked out by the sqlt hook test
 # CustomSql tests the horrific/deprecated ->name(\$sql) hack
-# YearXXXXCDs are views
+# YearXXXXCDs and NoViewDefinition are views
 #
 my @sources = grep
   { $_ !~ /^ (?: Dummy | CustomSql | Year\d{4}CDs ) $/x }
@@ -62,6 +63,27 @@ my @sources = grep
        }
 }
 
+{ 
+    {
+        package # hide from PAUSE
+            DBICTest::Schema::NoViewDefinition;
+
+        use base qw/DBICTest::BaseResult/;
+
+        __PACKAGE__->table_class('DBIx::Class::ResultSource::View');
+        __PACKAGE__->table('noviewdefinition');
+
+        1;
+    }
+
+    my $schema_invalid_view = $schema->clone;
+    $schema_invalid_view->register_class('NoViewDefinition', 'DBICTest::Schema::NoViewDefinition');
+
+    throws_ok { create_schema({ schema => $schema_invalid_view }) }
+        qr/view noviewdefinition is missing a view_definition/,
+        'parser detects views with a view_definition';
+}
+
 done_testing;
 
 sub create_schema {
@@ -80,7 +102,7 @@ sub create_schema {
        my $sqlt = SQL::Translator->new( $sqltargs );
 
        $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
-       return $sqlt->translate({ data => $schema }) or die $sqlt->error;
+       return $sqlt->translate({ data => $schema }) || die $sqlt->error;
 }
 
 sub get_table {