switch tests to Test::TempDir::Tiny to enable parallelization
[dbsrgits/DBIx-Class-Fixtures.git] / t / 04-dump-fetch.t
1 #!perl
2
3 use DBIx::Class::Fixtures;
4 use Test::More tests => 11;
5 use lib qw(t/lib);
6 use DBICTest;
7 use Path::Class;
8 use Data::Dumper;
9 use Test::TempDir::Tiny;
10 use IO::All;
11
12 my $tempdir = tempdir;
13
14 # set up and populate schema
15 ok(my $schema = DBICTest->init_schema(db_dir => $tempdir), 'got schema');
16
17 my $config_dir = io->catfile(qw't var configs')->name;
18
19 # do dump
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');
22
23 # check dump is 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');
27
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");
32 }
33
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");
40 }
41
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");
48 }
49
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');
53
54
55