3 use DBIx::Class::Fixtures;
4 use Test::More tests => 11;
10 # set up and populate schema
11 ok(my $schema = DBICTest->init_schema(), 'got schema');
13 my $config_dir = 't/var/configs';
16 ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
17 ok($fixtures->dump({ config => 'fetch.json', schema => $schema, directory => 't/var/fixtures' }), 'fetch dump executed okay');
20 my $dir = dir('t/var/fixtures/artist');
21 my @children = $dir->children;
22 is(scalar(@children), 2, 'right number of artist fixtures created');
24 # check both artists dumped
25 foreach my $id (1, 2) {
26 my $artist_fix_file = dir($dir, $id . '.fix');
27 ok(-e $artist_fix_file, "artist $id dumped okay");
30 # check all of artist1's cds were fetched
31 my $artist1 = $schema->resultset('Artist')->find(1);
32 my @artist1_cds = $artist1->cds->all;
33 foreach my $cd (@artist1_cds) {
34 my $cd_fix_file = dir('t/var/fixtures', 'cd', $cd->id . '.fix');
35 ok(-e $cd_fix_file, "artist1's cd rel dumped okay");
38 # check only cds matching artist2's cond were fetched
39 my $artist2 = $schema->resultset('Artist')->find(2);
40 my @artist2_cds = $artist2->cds->search({ year => { '>' => 2002 } });
41 foreach my $cd (@artist2_cds) {
42 my $cd_fix_file = dir('t/var/fixtures', 'cd', $cd->id . '.fix');
43 ok(-e $cd_fix_file, "artist2's cd rel dumped okay");
46 my $cd_dir = dir('t/var/fixtures/cd');
47 @children = $cd_dir->children;
48 is(scalar(@children), scalar(@artist1_cds) + scalar(@artist2_cds), 'no extra cd fixtures dumped');