[Bast-commits] r8284 - in branches/DBIx-Class-Schema-Loader/current:
lib/DBIx/Class/Schema/Loader t t/lib
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Mon Jan 11 22:43:44 GMT 2010
Author: caelum
Date: 2010-01-11 22:43:43 +0000 (Mon, 11 Jan 2010)
New Revision: 8284
Modified:
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm
branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t
branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_mssql_extra_tests.pm
Log:
add test for bad view in mssql
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm 2010-01-11 22:42:30 UTC (rev 8283)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm 2010-01-11 22:43:43 UTC (rev 8284)
@@ -118,6 +118,14 @@
}
else {
warn "Bad table or view '$table', ignoring: $@\n";
+ local $@;
+ eval {
+ my $schema = $self->schema;
+ # in older DBIC it's a private method
+ my $unregister = $schema->can('unregister_source')
+ || $schema->can('_unregister_source');
+ $schema->$unregister($self->_table2moniker($table));
+ };
}
}
Modified: branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t 2010-01-11 22:42:30 UTC (rev 8283)
+++ branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t 2010-01-11 22:43:43 UTC (rev 8284)
@@ -425,8 +425,7 @@
foreach my $source_name ($schema->sources) {
my $table_name = $schema->source($source_name)->from;
$monikers{$table_name} = $source_name;
- $classes{$table_name} = "${SCHEMA_CLASS}::" . (
- $loader_opts{use_namespaces} ? 'Result::' : '') . $source_name;
+ $classes{$table_name} = $schema->source($source_name)->result_class;
}
return {
Modified: branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm 2010-01-11 22:42:30 UTC (rev 8283)
+++ branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm 2010-01-11 22:43:43 UTC (rev 8284)
@@ -123,7 +123,7 @@
my $expected_count = 34;
- $expected_count += @{ $self->{extra}{drop} || [] };
+ $expected_count += @{ $self->{extra}{create} || [] };
$expected_count -= grep /CREATE TABLE/, @statements_inline_rels
if $self->{no_inline_rels};
@@ -140,6 +140,10 @@
$warn_count++ for grep /^Bad table or view/, @loader_warnings;
+ my $vendor = $self->{vendor};
+ $warn_count++ for grep /${vendor}_\S+ has no primary key/,
+ @loader_warnings;
+
if($self->{skip_rels}) {
SKIP: {
is(scalar(@loader_warnings), $warn_count, "No loader warnings")
Modified: branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_mssql_extra_tests.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_mssql_extra_tests.pm 2010-01-11 22:42:30 UTC (rev 8283)
+++ branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_mssql_extra_tests.pm 2010-01-11 22:43:43 UTC (rev 8284)
@@ -1,6 +1,7 @@
package dbixcsl_mssql_extra_tests;
use Test::More;
+use Test::Exception;
my $vendor = 'mssql';
@@ -9,6 +10,9 @@
$vendor = shift;
}
+# for cleanup in END
+my $saved_dbh;
+
sub extra { +{
create => [
qq{
@@ -26,9 +30,22 @@
ts DATETIME DEFAULT getdate()
)
},
+ qq{
+ CREATE TABLE ${vendor}_loader_test3 (
+ id INT IDENTITY NOT NULL PRIMARY KEY
+ )
+ },
+ qq{
+ CREATE VIEW ${vendor}_loader_test4 AS
+ SELECT * FROM ${vendor}_loader_test3
+ },
],
- drop => [ "[${vendor}_loader_test1.dot]", "${vendor}_loader_test2" ],
- count => 13,
+ drop => [
+ "[${vendor}_loader_test1.dot]",
+ "${vendor}_loader_test2",
+ "${vendor}_loader_test3"
+ ],
+ count => 15,
run => sub {
my ($schema, $monikers, $classes) = @_;
@@ -84,7 +101,35 @@
is $identity_col_info->{is_auto_increment}, 1,
q{'INT IDENTITY' column has is_auto_increment => 1};
+
+# Test that a bad view (where underlying table is gone) is ignored.
+ $saved_dbh = $schema->storage->dbh;
+ $saved_dbh->do("DROP TABLE ${vendor}_loader_test3");
+
+ my @warnings;
+ {
+ local $SIG{__WARN__} = sub { push @warnings, $_[0] };
+ $schema->rescan;
+ }
+ ok ((grep /^Bad table or view '${vendor}_loader_test4'/, @warnings),
+ 'bad view ignored');
+
+ throws_ok {
+ $schema->resultset("${vendor_titlecased}LoaderTest4")
+ } qr/Can't find source/,
+ 'no source registered for bad view';
},
}}
+# Clean up the bad view, table will be cleaned up in drops
+END {
+ local $@;
+ eval {
+ $saved_dbh->do($_) for (
+"CREATE TABLE ${vendor}_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)",
+"DROP VIEW ${vendor}_loader_test4"
+ );
+ };
+}
+
1;
More information about the Bast-commits
mailing list