From: Luke Saunders Date: Fri, 1 Aug 2008 12:04:35 +0000 (+0000) Subject: set debug to 0 by default and made cleanup more precise X-Git-Tag: v1.001002~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=da25ed7c77159939031faf4e4e716f7d360c4af1;p=dbsrgits%2FDBIx-Class-Fixtures.git set debug to 0 by default and made cleanup more precise --- diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index 983899d..92c6486 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -370,7 +370,7 @@ sub new { my $self = { config_dir => $config_dir, _inherited_attributes => [qw/datetime_relative might_have rules/], - debug => $params->{debug}, + debug => $params->{debug} || 0, ignore_sql_errors => $params->{ignore_sql_errors} }; @@ -548,9 +548,16 @@ sub dump { $self->dump_object(@$entry); } - foreach my $dir ($output_dir->children) { - next if ($dir eq $tmp_output_dir); - $dir->remove || $dir->rmtree; + # clear existing output dir + foreach my $child ($output_dir->children) { + if ($child->is_dir) { + next if ($child eq $tmp_output_dir); + if (grep { $_ =~ /\.fix/ } $child->children) { + $child->rmtree; + } + } elsif ($child =~ /_dumper_version$/) { + $child->remove; + } } $self->msg("- moving temp dir to $output_dir"); diff --git a/t/10-dump-cleanup.t b/t/10-dump-cleanup.t new file mode 100644 index 0000000..2febc75 --- /dev/null +++ b/t/10-dump-cleanup.t @@ -0,0 +1,27 @@ +#!perl + +use DBIx::Class::Fixtures; +use Test::More tests => 4; +use lib qw(t/lib); +use DBICTest; +use Path::Class; +use Data::Dumper; + +# set up and populate schema +ok(my $schema = DBICTest->init_schema(), 'got schema'); + +my $config_dir = 't/var/configs'; + +# do dump +ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir }), 'object created with correct config dir'); + +my $output_dir = dir('t/var/fixtures'); +$output_dir->mkpath; +my $file = file($output_dir, 'test_file'); +my $fh = $file->open('w'); +print $fh 'test file'; +$fh->close; + +ok($fixtures->dump({ config => 'simple.json', schema => $schema, directory => 't/var/fixtures' }), 'simple dump executed okay'); + +ok(-e $file, 'file still exists');