3 use DBIx::Class::Fixtures;
4 use Test::More tests => 11;
9 use Test::TempDir::Tiny;
12 my $tempdir = tempdir;
14 # set up and populate schema
15 ok(my $schema = DBICTest->init_schema(db_dir => $tempdir), 'got schema');
17 my $config_dir = io->catfile(qw't var configs')->name;
20 ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
21 ok($fixtures->dump({ config => 'fetch.json', schema => $schema, directory => $tempdir }), 'fetch dump executed okay');
24 my $dir = dir(io->catfile($tempdir, qw'artist')->name);
25 my @children = $dir->children;
26 is(scalar(@children), 3, 'right number of artist fixtures created');
28 # check both artists dumped
29 foreach my $id (1, 2) {
30 my $artist_fix_file = dir($dir, $id . '.fix');
31 ok(-e $artist_fix_file, "artist $id dumped okay");
34 # check all of artist1's cds were fetched
35 my $artist1 = $schema->resultset('Artist')->find(1);
36 my @artist1_cds = $artist1->cds->all;
37 foreach my $cd (@artist1_cds) {
38 my $cd_fix_file = dir($tempdir, 'CD', $cd->id . '.fix');
39 ok(-e $cd_fix_file, "artist1's cd rel dumped okay");
42 # check only cds matching artist2's cond were fetched
43 my $artist2 = $schema->resultset('Artist')->find(2);
44 my @artist2_cds = $artist2->cds->search({ year => { '>' => 2002 } });
45 foreach my $cd (@artist2_cds) {
46 my $cd_fix_file = dir($tempdir, 'CD', $cd->id . '.fix');
47 ok(-e $cd_fix_file, "artist2's cd rel dumped okay");
50 my $cd_dir = dir(io->catfile($tempdir, qw'CD')->name);
51 @children = $cd_dir->children;
52 is(scalar(@children), scalar(@artist1_cds) + scalar(@artist2_cds), 'no extra cd fixtures dumped');