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