Merge 'sqlt_parser_view' into 'trunk'
Peter Rabbitson [Fri, 18 Dec 2009 13:55:53 +0000 (13:55 +0000)]
r8150@Thesaurus (orig r8138):  abraxxa | 2009-12-17 23:22:07 +0100
Views without a view_definition won't be added to the SQL::Translator::Schema by the parser + tests

r8151@Thesaurus (orig r8139):  abraxxa | 2009-12-17 23:23:33 +0100
test cleanups

r8153@Thesaurus (orig r8141):  abraxxa | 2009-12-18 14:34:14 +0100
throw_exception if view_definition is missing instead of silent skipping + test changes

r8154@Thesaurus (orig r8142):  abraxxa | 2009-12-18 14:40:32 +0100
use Test::Exception

r8155@Thesaurus (orig r8143):  abraxxa | 2009-12-18 14:42:00 +0100
fixed Changes

r8156@Thesaurus (orig r8144):  abraxxa | 2009-12-18 14:44:52 +0100
test cleanups

r8157@Thesaurus (orig r8145):  ribasushi | 2009-12-18 14:46:26 +0100
Another bitr

Changes
lib/SQL/Translator/Parser/DBIx/Class.pm
t/99dbic_sqlt_parser.t

diff --git a/Changes b/Changes
index 9a3ba9d..1b5b7d6 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,8 @@ Revision history for DBIx::Class
         - might_have/has_one now warn if applied calling class's column
           has is_nullable set to true.
         - Cookbook POD fix for add_drop_table instead of add_drop_tables
+        - Views without a view_definition will throw an exception when
+          parsed by SQL::Translator::Parser::DBIx::Class
 
 0.08115 2009-12-10 09:02:00 (CST)
         - Real limit/offset support for MSSQL server (via Row_Number)
index bb40c91..c8235e3 100644 (file)
@@ -289,6 +289,9 @@ EOW
         # Its possible to have multiple DBIC source using same table
         next if $views{$view_name}++;
 
+        $dbicschema->throw_exception ("view $view_name is missing a view_definition")
+            unless $source->view_definition;
+
         my $view = $schema->add_view (
           name => $view_name,
           fields => [ $source->columns ],
index d4b1a9f..2855ff1 100644 (file)
@@ -2,6 +2,7 @@
 use strict;
 use warnings;
 use Test::More;
+use Test::Exception;
 use lib qw(t/lib);
 use DBICTest;
 
@@ -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 {