diff --git a/Makefile.PL b/Makefile.PL index ce3c5d5..936dc1e 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -49,7 +49,8 @@ my %WriteMakefileArgs = ( "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, - "Test::More" => "0.98" + "Test::More" => "0.98", + "Test::Warnings" => 0, }, "VERSION" => "1.001036", "test" => { diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index c979849..6796692 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -813,7 +813,7 @@ sub dump_object { }; my $subsre = join( '|', keys %$subs ); - $_ =~ s{__($subsre)(?:\((.+?)\))?__}{ $subs->{ $1 }->( $self, $2 ? split( /,/, $2 ) : () ) }eg; + $_ =~ s{__($subsre)(?:\((.+?)\))?__}{ $subs->{ $1 }->( $self, $2 ? split( /,/, $2 ) : () ) }eg if (defined $_); return $_; } diff --git a/t/20-nulls.t b/t/20-nulls.t new file mode 100644 index 0000000..82b2969 --- /dev/null +++ b/t/20-nulls.t @@ -0,0 +1,57 @@ +#!perl + +use DBIx::Class::Fixtures; +use Test::More tests => 10; +use lib qw(t/lib); +use DBICTest; +use Path::Class; +use Data::Dumper; +use Test::TempDir::Tiny; +use IO::All; +use Test::Warnings; + +my $tempdir = tempdir; + +# set up and populate schema +ok(my $schema = DBICTest->init_schema(db_dir => $tempdir), 'got schema'); + +my $config_dir = io->catfile(qw't var configs')->name; + +# do dump +ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); + +ok($fixtures->dump({ config => 'nulls.json', schema => $schema, directory => $tempdir }), 'simple dump executed okay'); + +{ + # check dump is okay + my $dir = dir(io->catfile($tempdir, qw'artist')->name); + my @children = $dir->children; + is(scalar(@children), 1, 'right number of fixtures created'); +} + +{ + # check dump is okay + my $dir = dir(io->catfile($tempdir, qw'CD')->name); + my @children = $dir->children; + is(scalar(@children), 1, 'right number of fixtures created'); +} + +# do dump +ok($fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); + +ok($fixtures->dump({ config => 'not-nulls.json', schema => $schema, directory => $tempdir }), 'simple dump executed okay'); + +{ + # check dump is okay + my $dir = dir(io->catfile($tempdir, qw'artist')->name); + my @children = $dir->children; + is(scalar(@children), 5, 'right number of fixtures created'); +} + +{ + # check dump is okay + my $dir = dir(io->catfile($tempdir, qw'CD')->name); + my @children = $dir->children; + is(scalar(@children), 6, 'right number of fixtures created'); +} + diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index 8b6d155..217aaf4 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -155,6 +155,7 @@ sub populate_schema { [ 2, 'Random Boy Band' ], [ 3, 'We Are Goth' ], [ 4, '' ], # Test overridden new will default name to "Test Name" using use_create => 1. + [ 5, undef ], # The artist formerly known as *silence*. [ 32948, 'Big PK' ], ]); @@ -171,6 +172,7 @@ sub populate_schema { [ 4, 2, "Generic Manufactured Singles", 2001 ], [ 5, 2, "Unicode Chars ™ © • † ∑ α β « » → …", 2015 ], [ 6, 3, "Übertreibung älterer Umlaute with us", 1998 ], + [ 7, 5, "Cosmic Nothingness", 2016 ], ]); $schema->populate('Tag', [ diff --git a/t/var/configs/not-nulls.json b/t/var/configs/not-nulls.json new file mode 100644 index 0000000..f244596 --- /dev/null +++ b/t/var/configs/not-nulls.json @@ -0,0 +1,16 @@ +{ + "might_have": { + "fetch": 0 + }, + "has_many": { + "fetch": 0 + }, + "sets": [{ + "class": "Artist", + "cond": { "me.name": { "!=": null } }, + "quantity": "all", + "fetch": [{ + "rel": "cds" + }] + }] +} diff --git a/t/var/configs/nulls.json b/t/var/configs/nulls.json new file mode 100644 index 0000000..692dfd9 --- /dev/null +++ b/t/var/configs/nulls.json @@ -0,0 +1,16 @@ +{ + "might_have": { + "fetch": 0 + }, + "has_many": { + "fetch": 0 + }, + "sets": [{ + "class": "Artist", + "cond": { "me.name": { "=": null } }, + "quantity": "all", + "fetch": [{ + "rel": "cds" + }] + }] +}