3 use DBIx::Class::Fixtures;
4 use Test::More tests => 7;
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 => 'multiple-has-many.json', schema => $schema, directory => $tempdir }), 'fetch dump executed okay');
24 my $dir = dir($tempdir);
26 ok( -e io->catfile($tempdir, qw'producer')->name, "We fetched some producers" );
27 ok( -e io->catfile($tempdir, qw'cd_to_producer')->name, "We fetched some cd producer xrefs" );
28 ok( -e io->catfile($tempdir, qw'CD')->name, "We fetched some cds" );
29 ok( -e io->catfile($tempdir, qw'artist')->name, "We fetched some artists" );
32 while ( my ($dirname, $sourcename) = each %dirs ) {
33 my $this_dir = dir($dir, $dirname);
36 my $cd_dir = dir($dir, 'cd');
37 my $track_dir = dir($dir, 'track');
39 # check only artist1's cds that matched the rule were fetched
40 my $artist1 = $schema->resultset('Artist')->find(1);
41 my $artist1_cds = $artist1->cds;
42 while (my $a1_cd = $artist1_cds->next) {
43 my $cd_fix_file = file($cd_dir, $a1_cd->id . '.fix');
44 if ($a1_cd->tags->search({ tag => 'Cheesy' })->count) {
45 ok(-e $cd_fix_file, 'cd matching rule fetched');
47 isnt(-e $cd_fix_file, 1, 'cd not matching rule not fetched');
51 # check only cds' tracks that matched the rule were fetched
52 foreach my $cd_fix_file ($cd_dir->children) {
53 my $HASH1; eval($cd_fix_file->slurp());
54 is(ref $HASH1, 'HASH', 'cd fixture evals into hash');
56 my $cd = $schema->resultset('CD')->find($HASH1->{cdid});
57 foreach my $track ($cd->tracks->all) {
58 my $track_fix_file = file($track_dir, $track->id . '.fix');
59 if ($track->get_column('position') eq 2) {
60 is(-e $track_fix_file, 1, 'track matching rule fetched');
62 isnt(-e $track_fix_file, 1, 'track not matching rule not fetched');