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; |
01a3246a |
9 | use Test::TempDir::Tiny; |
66d02e24 |
10 | use IO::All; |
610be089 |
11 | |
01a3246a |
12 | my $tempdir = tempdir; |
13 | |
610be089 |
14 | # set up and populate schema |
01a3246a |
15 | ok(my $schema = DBICTest->init_schema(db_dir => $tempdir), 'got schema'); |
610be089 |
16 | |
66d02e24 |
17 | my $config_dir = io->catfile(qw't var configs')->name; |
610be089 |
18 | |
19 | # do dump |
20 | ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); |
01a3246a |
21 | ok($fixtures->dump({ config => 'multiple-has-many.json', schema => $schema, directory => $tempdir }), 'fetch dump executed okay'); |
610be089 |
22 | |
23 | # check dump is okay |
01a3246a |
24 | my $dir = dir($tempdir); |
610be089 |
25 | |
01a3246a |
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" ); |
610be089 |
30 | |
31 | __END__ |
32 | while ( my ($dirname, $sourcename) = each %dirs ) { |
33 | my $this_dir = dir($dir, $dirname); |
34 | } |
35 | |
36 | my $cd_dir = dir($dir, 'cd'); |
37 | my $track_dir = dir($dir, 'track'); |
38 | |
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'); |
46 | } else { |
47 | isnt(-e $cd_fix_file, 1, 'cd not matching rule not fetched'); |
48 | } |
49 | } |
50 | |
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'); |
55 | |
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'); |
61 | } else { |
62 | isnt(-e $track_fix_file, 1, 'track not matching rule not fetched'); |
63 | } |
64 | } |
65 | } |
66 | |