Commit | Line | Data |
610be089 |
1 | #!perl |
2 | |
3 | use DBIx::Class::Fixtures; |
4 | use Test::More tests => 7; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | use Path::Class; |
8 | use Data::Dumper; |
9 | |
10 | # set up and populate schema |
11 | ok(my $schema = DBICTest->init_schema(), 'got schema'); |
12 | |
13 | my $config_dir = 't/var/configs'; |
14 | |
15 | # do dump |
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 => 'multiple-has-many.json', schema => $schema, directory => 't/var/fixtures' }), 'fetch dump executed okay'); |
18 | |
19 | # check dump is okay |
20 | my $dir = dir('t/var/fixtures'); |
21 | |
22 | ok( -e 't/var/fixtures/producer', "We fetched some producers" ); |
23 | ok( -e 't/var/fixtures/cd_to_producer', "We fetched some cd/producer xrefs" ); |
dcdf675f |
24 | ok( -e 't/var/fixtures/CD', "We fetched some cds" ); |
610be089 |
25 | ok( -e 't/var/fixtures/artist', "We fetched some artists" ); |
26 | |
27 | __END__ |
28 | while ( my ($dirname, $sourcename) = each %dirs ) { |
29 | my $this_dir = dir($dir, $dirname); |
30 | } |
31 | |
32 | my $cd_dir = dir($dir, 'cd'); |
33 | my $track_dir = dir($dir, 'track'); |
34 | |
35 | # check only artist1's cds that matched the rule were fetched |
36 | my $artist1 = $schema->resultset('Artist')->find(1); |
37 | my $artist1_cds = $artist1->cds; |
38 | while (my $a1_cd = $artist1_cds->next) { |
39 | my $cd_fix_file = file($cd_dir, $a1_cd->id . '.fix'); |
40 | if ($a1_cd->tags->search({ tag => 'Cheesy' })->count) { |
41 | ok(-e $cd_fix_file, 'cd matching rule fetched'); |
42 | } else { |
43 | isnt(-e $cd_fix_file, 1, 'cd not matching rule not fetched'); |
44 | } |
45 | } |
46 | |
47 | # check only cds' tracks that matched the rule were fetched |
48 | foreach my $cd_fix_file ($cd_dir->children) { |
49 | my $HASH1; eval($cd_fix_file->slurp()); |
50 | is(ref $HASH1, 'HASH', 'cd fixture evals into hash'); |
51 | |
52 | my $cd = $schema->resultset('CD')->find($HASH1->{cdid}); |
53 | foreach my $track ($cd->tracks->all) { |
54 | my $track_fix_file = file($track_dir, $track->id . '.fix'); |
55 | if ($track->get_column('position') eq 2) { |
56 | is(-e $track_fix_file, 1, 'track matching rule fetched'); |
57 | } else { |
58 | isnt(-e $track_fix_file, 1, 'track not matching rule not fetched'); |
59 | } |
60 | } |
61 | } |
62 | |