Fix errors from resultset components (and move tests into t/90ensure_class_loaded...
Ash Berlin [Tue, 11 Mar 2008 15:03:34 +0000 (15:03 +0000)]
Changes
lib/DBIx/Class/ResultSet.pm
t/90ensure_class_loaded.t
t/98source_load_error.t [deleted file]
t/lib/DBICErrorTest/ResultSet/WithError.pm [deleted file]
t/lib/DBICErrorTest/Schema/SourceWithError.pm [deleted file]
t/lib/DBICTest/SyntaxErrorComponent3.pm [moved from t/lib/DBICErrorTest/SyntaxError.pm with 100% similarity]

diff --git a/Changes b/Changes
index 3a9c537..0d95297 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,7 @@ Revision history for DBIx::Class
         - is_deferable support on relations used by the SQL::Translator
           parser (Anders Nor Berle)
         - Refactored DBIx::Class::Schema::Versioned
+        - Syntax errors from resultset components are now reported correctly
 
 0.08010 2008-03-01 10:30
         - Fix t/94versioning.t so it passes with latest SQL::Translator
index 775d032..b30efa2 100644 (file)
@@ -2132,7 +2132,12 @@ See L<DBIx::Class::Schema/throw_exception> for details.
 
 sub throw_exception {
   my $self=shift;
-  $self->_source_handle->schema->throw_exception(@_);
+  if (ref $self) {
+    $self->_source_handle->schema->throw_exception(@_)
+  } else {
+    croak(@_);
+  }
+
 }
 
 # XXX: FIXME: Attributes docs need clearing up
index c901d06..3fc828e 100644 (file)
@@ -13,7 +13,7 @@ BEGIN {
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 19;
+plan tests => 20;
 
 # Test ensure_class_found
 ok( $schema->ensure_class_found('DBIx::Class::Schema'),
@@ -72,4 +72,16 @@ ok( Class::Inspector->loaded('DBICTest::FakeComponent'),
         'load_optional_class(DBICTest::SyntaxErrorComponent2) threw ok' );
 }
 
+
+eval {
+  package Fake::ResultSet;
+
+  use base 'DBIx::Class::ResultSet';
+
+  __PACKAGE__->load_components('+DBICTest::SyntaxErrorComponent3');
+};
+
+# Make sure the errors in components of resultset classes are reported right.
+like($@, qr!\Qsyntax error at t/lib/DBICTest/SyntaxErrorComponent3.pm!, "Errors from RS components reported right");
+
 1;
diff --git a/t/98source_load_error.t b/t/98source_load_error.t
deleted file mode 100644 (file)
index 620acda..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More tests => 1;
-
-use lib qw(t/lib);
-eval {
-  package DBICErrorTest::Schema;
-
-  use base 'DBIx::Class::Schema';
-  __PACKAGE__->load_classes('SourceWithError');
-};
-
-# Make sure the errors in components of resultset classes are reported right.
-like($@, qr!syntax error at t/lib/DBICErrorTest/SyntaxError.pm!);
diff --git a/t/lib/DBICErrorTest/ResultSet/WithError.pm b/t/lib/DBICErrorTest/ResultSet/WithError.pm
deleted file mode 100644 (file)
index 5e7a913..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-package DBICErrorTest::ResultSet::WithError;
-
-use strict;
-use warnings;
-
-use base 'DBIx::Class::ResultSet';
-
-__PACKAGE__->load_components('+DBICErrorTest::SyntaxError');
-
-1;
diff --git a/t/lib/DBICErrorTest/Schema/SourceWithError.pm b/t/lib/DBICErrorTest/Schema/SourceWithError.pm
deleted file mode 100644 (file)
index af23af8..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-package DBICErrorTest::Schema::SourceWithError;
-
-use strict;
-use warnings;
-
-use base 'DBIx::Class';
-__PACKAGE__->load_components('Core');
-__PACKAGE__->table('foo');
-#__PACKAGE__->load_components('+DBICErrorTest::SyntaxError');
-require DBICErrorTest::ResultSet::WithError;
-__PACKAGE__->resultset_class('DBICErrorTest::ResultSet::WithError');
-
-1;