clean up the query from table stuff
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 40overwrite_modifications.t
CommitLineData
9cb983b3 1use strict;
2use Test::More tests => 3;
3use Test::Exception;
4use lib qw(t/lib);
5use make_dbictest_db;
6
7use File::Copy;
8use File::Spec;
9use File::Temp qw/ tempdir tempfile /;
10
11use DBIx::Class::Schema::Loader;
12
13my $tempdir = tempdir( CLEANUP => 1 );
14my $foopm = File::Spec->catfile( $tempdir, qw| DBICTest Schema Overwrite_modifications Foo.pm |);
15dump_schema();
16
17# check that we dumped
18ok( -f $foopm, 'looks like it dumped' );
19
20# now modify one of the files
21{
22 open my $in, '<', $foopm or die "$! reading $foopm";
23 my ($tfh,$temp) = tempfile( UNLINK => 1);
24 while(<$in>) {
25 s/"bars"/"somethingelse"/;
26 print $tfh $_;
27 }
28 close $tfh;
29 copy( $temp, $foopm );
30}
31
32# and dump again without overwrites
33throws_ok {
34 dump_schema();
35} qr/mismatch/, 'throws error dumping without overwrite_modifications';
36
37# and then dump with overwrite
38lives_ok {
39 dump_schema( overwrite_modifications => 1 );
40} 'does not throw when dumping with overwrite_modifications';
41
42sub dump_schema {
43
44 # need to poke _loader_invoked in order to be able to rerun the
45 # loader multiple times.
46 DBICTest::Schema::Overwrite_modifications->_loader_invoked(0)
47 if @DBICTest::Schema::Overwrite_modifications::ISA;
48
cb68a7cc 49 local $SIG{__WARN__} = sub {
50 warn @_
51 unless $_[0] =~ /^Dumping manual schema|^Schema dump completed/;
52 };
9cb983b3 53 DBIx::Class::Schema::Loader::make_schema_at( 'DBICTest::Schema::Overwrite_modifications',
54 { dump_directory => $tempdir,
55 @_,
56 },
57 [ $make_dbictest_db::dsn ],
58 );
59}