[Bast-commits] r8208 - in branches/DBIx-Class-Schema-Loader/current: . t

rbuels at dev.catalyst.perl.org rbuels at dev.catalyst.perl.org
Fri Jan 1 02:32:13 GMT 2010


Author: rbuels
Date: 2010-01-01 02:32:12 +0000 (Fri, 01 Jan 2010)
New Revision: 8208

Added:
   branches/DBIx-Class-Schema-Loader/current/t/40overwrite_modifications.t
Modified:
   branches/DBIx-Class-Schema-Loader/current/Makefile.PL
Log:
added tests for overwrite_modifications option

Modified: branches/DBIx-Class-Schema-Loader/current/Makefile.PL
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/Makefile.PL	2009-12-31 21:17:06 UTC (rev 8207)
+++ branches/DBIx-Class-Schema-Loader/current/Makefile.PL	2010-01-01 02:32:12 UTC (rev 8208)
@@ -3,12 +3,14 @@
 name           'DBIx-Class-Schema-Loader';
 all_from       'lib/DBIx/Class/Schema/Loader.pm';
 
+test_requires 'Test::Exception';
 test_requires 'Test::More'    => '0.94';
 test_requires 'DBI'           => '1.56';
 test_requires 'DBD::SQLite'   => '1.12';
+test_requires 'File::Copy';
+test_requires 'File::Temp'    => '0.16';
 test_requires 'File::Path'    => '2.07';
 test_requires 'IPC::Open3'    => 0;
-test_requires 'Test::Exception';
 
 requires 'File::Spec'                  => 0;
 requires 'Scalar::Util'                => 0;

Added: branches/DBIx-Class-Schema-Loader/current/t/40overwrite_modifications.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/40overwrite_modifications.t	                        (rev 0)
+++ branches/DBIx-Class-Schema-Loader/current/t/40overwrite_modifications.t	2010-01-01 02:32:12 UTC (rev 8208)
@@ -0,0 +1,55 @@
+use strict;
+use Test::More tests => 3;
+use Test::Exception;
+use lib qw(t/lib);
+use make_dbictest_db;
+
+use File::Copy;
+use File::Spec;
+use File::Temp qw/ tempdir tempfile /;
+
+use DBIx::Class::Schema::Loader;
+
+my $tempdir = tempdir( CLEANUP => 1 );
+my $foopm = File::Spec->catfile( $tempdir, qw| DBICTest Schema Overwrite_modifications Foo.pm |);
+dump_schema();
+
+# check that we dumped
+ok( -f $foopm, 'looks like it dumped' );
+
+# now modify one of the files
+{
+    open my $in, '<', $foopm or die "$! reading $foopm";
+    my ($tfh,$temp) = tempfile( UNLINK => 1);
+    while(<$in>) {
+	s/"bars"/"somethingelse"/;
+	print $tfh $_;
+    }
+    close $tfh;
+    copy( $temp, $foopm );
+}
+
+# and dump again without overwrites
+throws_ok {
+    dump_schema();
+} qr/mismatch/, 'throws error dumping without overwrite_modifications';
+
+# and then dump with overwrite
+lives_ok {
+    dump_schema( overwrite_modifications => 1 );
+} 'does not throw when dumping with overwrite_modifications';
+
+sub dump_schema {
+
+    # need to poke _loader_invoked in order to be able to rerun the
+    # loader multiple times.
+    DBICTest::Schema::Overwrite_modifications->_loader_invoked(0)
+	  if @DBICTest::Schema::Overwrite_modifications::ISA;
+
+    DBIx::Class::Schema::Loader::make_schema_at( 'DBICTest::Schema::Overwrite_modifications',
+						 { dump_directory => $tempdir,
+						   @_,
+						 },
+						 [ $make_dbictest_db::dsn ],
+					       );
+}




More information about the Bast-commits mailing list