Commit | Line | Data |
5eab44a9 |
1 | #!perl |
2 | |
3 | use DBIx::Class::Fixtures; |
570384ac |
4 | use Test::More tests => 15; |
5eab44a9 |
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 => 'rules.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 | my $cd_dir = dir($dir, 'cd'); |
22 | my $track_dir = dir($dir, 'track'); |
23 | |
24 | # check only artist1's cds that matched the rule were fetched |
25 | my $artist1 = $schema->resultset('Artist')->find(1); |
26 | my $artist1_cds = $artist1->cds; |
27 | while (my $a1_cd = $artist1_cds->next) { |
28 | my $cd_fix_file = file($cd_dir, $a1_cd->id . '.fix'); |
29 | if ($a1_cd->tags->search({ tag => 'Cheesy' })->count) { |
30 | ok(-e $cd_fix_file, 'cd matching rule fetched'); |
31 | } else { |
32 | isnt(-e $cd_fix_file, 1, 'cd not matching rule not fetched'); |
33 | } |
34 | } |
35 | |
36 | # check only cds' tracks that matched the rule were fetched |
37 | foreach my $cd_fix_file ($cd_dir->children) { |
38 | my $HASH1; eval($cd_fix_file->slurp()); |
39 | is(ref $HASH1, 'HASH', 'cd fixture evals into hash'); |
40 | |
41 | my $cd = $schema->resultset('CD')->find($HASH1->{cdid}); |
42 | foreach my $track ($cd->tracks->all) { |
43 | my $track_fix_file = file($track_dir, $track->id . '.fix'); |
44 | if ($track->get_column('position') eq 2) { |
45 | is(-e $track_fix_file, 1, 'track matching rule fetched'); |
46 | } else { |
47 | isnt(-e $track_fix_file, 1, 'track not matching rule not fetched'); |
48 | } |
49 | } |
50 | } |
570384ac |
51 | |
52 | ok $fixtures->available_config_sets, 'Found sets'; |