From: Rafael Kitover Date: Sat, 28 Nov 2009 07:36:00 +0000 (+0000) Subject: add test for norewrite X-Git-Tag: 0.04999_11~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4daef04f012fb7cb9df41a866a1d4e2715670c9d;p=dbsrgits%2FDBIx-Class-Schema-Loader.git add test for norewrite --- diff --git a/Changes b/Changes index 0e8117a..de5f14f 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - added test for norewrite feature - fix default_value for MSSQL 0.04999_10 2009-10-31 12:28:53 diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 5d146ec..878d028 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -423,6 +423,9 @@ sub _load_tables { sub _reload_classes { my ($self, @tables) = @_; + # so that we don't repeat custom sections + @INC = grep $_ ne $self->dump_directory, @INC; + $self->_dump_to_dir(map { $self->classes->{$_} } @tables); unshift @INC, $self->dump_directory; diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 674ec2e..cc9768b 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -8,6 +8,8 @@ use DBIx::Class::Schema::Loader; use Class::Unload; use File::Path; use DBI; +use Digest::MD5; +use File::Find 'find'; my $DUMP_DIR = './t/_common_dump'; rmtree $DUMP_DIR; @@ -54,7 +56,7 @@ sub _monikerize { sub run_tests { my $self = shift; - plan tests => 3 + 134 + ($self->{extra}->{count} || 0); + plan tests => 3 + 135 + ($self->{extra}->{count} || 0); $self->create(); @@ -616,11 +618,8 @@ sub test_schema { } } - # rescan test + # rescan and norewrite test SKIP: { - skip $self->{skip_rels}, 4 if $self->{skip_rels}; - skip "Can't rescan dumped schema", 4 if $self->{dump}; - my @statements_rescan = ( qq{ CREATE TABLE loader_test30 ( @@ -633,15 +632,47 @@ sub test_schema { q{ INSERT INTO loader_test30 (id,loader_test2) VALUES(321, 2) }, ); + # get md5 + my $digest = Digest::MD5->new; + + my $find_cb = sub { + return if -d; + return if $_ eq 'LoaderTest30.pm'; + + open my $fh, '<', $_ or die "Could not open $_ for reading: $!"; + binmode $fh; + $digest->addfile($fh); + }; + + find $find_cb, $DUMP_DIR; + + my $before_digest = $digest->digest; + my $dbh = $self->dbconnect(1); $dbh->do($_) for @statements_rescan; $dbh->disconnect; - my @new = $conn->rescan; + sleep 1; + + my @new = do { + # kill the 'Dumping manual schema' warnings + local $SIG{__WARN__} = sub {}; + $conn->rescan; + }; is_deeply(\@new, [ qw/LoaderTest30/ ], "Rescan"); + $digest = Digest::MD5->new; + find $find_cb, $DUMP_DIR; + my $after_digest = $digest->digest; + + is $before_digest, $after_digest, + 'dumped files are not rewritten when there is no modification'; + my $rsobj30 = $conn->resultset('LoaderTest30'); isa_ok($rsobj30, 'DBIx::Class::ResultSet'); + + skip 'no rels', 2 if $self->{skip_rels}; + my $obj30 = $rsobj30->find(123); isa_ok( $obj30->loader_test2, $class2);