From: Alexander Hartmaier Date: Fri, 18 Dec 2009 13:34:14 +0000 (+0000) Subject: throw_exception if view_definition is missing instead of silent skipping + test changes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ab7e74aa35788fa25e0e98245917c7f9f5e9318c;p=dbsrgits%2FDBIx-Class-Historic.git throw_exception if view_definition is missing instead of silent skipping + test changes --- diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 40389b3..c8235e3 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -289,7 +289,8 @@ EOW # Its possible to have multiple DBIC source using same table next if $views{$view_name}++; - next unless $source->view_definition; + $dbicschema->throw_exception ("view $view_name is missing a view_definition") + unless $source->view_definition; my $view = $schema->add_view ( name => $view_name, diff --git a/t/99dbic_sqlt_parser.t b/t/99dbic_sqlt_parser.t index 72c1340..f795905 100644 --- a/t/99dbic_sqlt_parser.t +++ b/t/99dbic_sqlt_parser.t @@ -63,24 +63,41 @@ my @sources = grep } { - #my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } }); - my $sqlt_schema = create_schema({ schema => $schema }); - - my @views = $sqlt_schema->get_views; + { + package # hide from PAUSE + DBICTest::Schema::NoViewDefinition; + + use base qw/DBICTest::BaseResult/; - # the following views are skipped: - # Year1999CDs is virtual - # NoViewDefinition has no view_definition - is(scalar @views, 1, "number of views ok"); + __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); + __PACKAGE__->table('noviewdefinition'); - foreach my $view (@views) { - ok($view->is_valid, "view " . $view->name . " is valid"); + 1; } - my @expected_view_names = (qw/ year2000cds /); - my @view_names = sort map { $_->name } @views; + my $schema_invalid_view = $schema->clone; + $schema_invalid_view->register_class('NoViewDefinition', 'DBICTest::Schema::NoViewDefinition'); - is_deeply( @view_names, @expected_view_names, "all expected views included int SQL::Translator schema" ); + eval { + my $sqlt_schema = create_schema({ schema => $schema_invalid_view }); + }; + like($@, qr/view noviewdefinition is missing a view_definition/, "parser detects views with a view_definition"); + +# my @views = $sqlt_schema->get_views; +# +# # the following views are skipped: +# # Year1999CDs is virtual +# # NoViewDefinition has no view_definition +# is(scalar @views, 1, "number of views ok"); +# +# foreach my $view (@views) { +# ok($view->is_valid, "view " . $view->name . " is valid"); +# } +# +# my @expected_view_names = (qw/ year2000cds /); +# my @view_names = sort map { $_->name } @views; +# +# is_deeply( @view_names, @expected_view_names, "all expected views included int SQL::Translator schema" ); } done_testing; @@ -101,7 +118,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 { diff --git a/t/lib/DBICTest/Schema.pm b/t/lib/DBICTest/Schema.pm index d6d03b5..a3e4484 100644 --- a/t/lib/DBICTest/Schema.pm +++ b/t/lib/DBICTest/Schema.pm @@ -22,7 +22,6 @@ __PACKAGE__->load_classes(qw/ Year1999CDs CustomSql Money - NoViewDefinition /, { 'DBICTest::Schema' => [qw/ LinerNotes diff --git a/t/lib/DBICTest/Schema/NoViewDefinition.pm b/t/lib/DBICTest/Schema/NoViewDefinition.pm deleted file mode 100644 index bf7783a..0000000 --- a/t/lib/DBICTest/Schema/NoViewDefinition.pm +++ /dev/null @@ -1,9 +0,0 @@ -package # hide from PAUSE - DBICTest::Schema::NoViewDefinition; - -use base qw/DBICTest::BaseResult/; - -__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); -__PACKAGE__->table('noviewdefinition'); - -1;