From: John Napiorkowski Date: Fri, 6 Mar 2015 00:26:57 +0000 (-0600) Subject: new test case with nested resultsources X-Git-Tag: v1.001_030~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=98692f581b2e6c9034b0c4fdc856b1554ccc63dd;p=dbsrgits%2FDBIx-Class-Fixtures.git new test case with nested resultsources --- diff --git a/t/19-complex-hierarchy.t b/t/19-complex-hierarchy.t index 4da70a5..8fa5598 100644 --- a/t/19-complex-hierarchy.t +++ b/t/19-complex-hierarchy.t @@ -1,7 +1,7 @@ #!perl use DBIx::Class::Fixtures; -use Test::More tests => 4; +use Test::More tests => 7; use lib qw(t/lib); use DBICTest; use Path::Class; @@ -20,37 +20,9 @@ ok my $artist = $schema->resultset("Artist")->find(1); ok my $washed_up = $artist->create_related('washed_up', +{}); ok $washed_up->fk_artistid; -__END__ -{ - # 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 => 'simple.json', schema => $schema, directory => io->catfile(qw't var fixtures')->name }), 'simple dump executed okay'); - - # check dump is okay - my $dir = dir(io->catfile(qw't var fixtures artist')->name); - ok(-e io->catfile(qw't var fixtures artist')->name, 'artist directory created'); - - my @children = $dir->children; - is(scalar(@children), 1, 'right number of fixtures created'); - - my $fix_file = $children[0]; - my $HASH1; eval($fix_file->slurp()); - is(ref $HASH1, 'HASH', 'fixture evals into hash'); - - is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys'); - - my $artist = $schema->resultset('Artist')->find($HASH1->{artistid}); - is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row'); - - $schema->resultset('Artist')->delete; # so we can create the row again on the next line - ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture'); -} - -{ - # do dump with hashref config - ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); - ok($fixtures->dump({ +ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); +ok($fixtures->dump({ config => { "might_have" => { "fetch" => 0 @@ -59,7 +31,7 @@ __END__ "fetch" => 0 }, "sets" => [{ - "class" => "Artist", + "class" => "Artist::WashedUp", "quantity" => 1 }] }, @@ -67,22 +39,11 @@ __END__ directory => io->catfile(qw't var fixtures')->name, }), 'simple dump executed okay'); - # check dump is okay - my $dir = dir(io->catfile(qw't var fixtures artist')->name); - ok(-e io->catfile(qw't var fixtures artist')->name, 'artist directory created'); - - my @children = $dir->children; - is(scalar(@children), 1, 'right number of fixtures created'); - - my $fix_file = $children[0]; - my $HASH1; eval($fix_file->slurp()); - is(ref $HASH1, 'HASH', 'fixture evals into hash'); - - is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys'); +ok( + $fixtures->dump({ + config => 'washed-up.json', + schema => $schema, + directory => io->catfile(qw't var fixtures')->name, + })); - my $artist = $schema->resultset('Artist')->find($HASH1->{artistid}); - is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row'); - $schema->resultset('Artist')->delete; # so we can create the row again on the next line - ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture'); -} diff --git a/t/var/configs/washed-up.json b/t/var/configs/washed-up.json new file mode 100644 index 0000000..ffcdc50 --- /dev/null +++ b/t/var/configs/washed-up.json @@ -0,0 +1,18 @@ +{ + "might_have" : { + "fetch" : 0 + }, + "belongs_to" : { + "fetch" : 0 + }, + "sets" : [ + { + "class" : "Artist::WashedUp", + "quantity" : "all" + } + ], + "has_many" : { + "fetch" : 0 + } +} +