Merge branch 'RsrchBoy-topic/parallelize-tests'
[dbsrgits/DBIx-Class-Fixtures.git] / t / 04-dump-fetch.t
CommitLineData
5eab44a9 1#!perl
2
3use DBIx::Class::Fixtures;
4use Test::More tests => 11;
5use lib qw(t/lib);
6use DBICTest;
7use Path::Class;
8use Data::Dumper;
01a3246a 9use Test::TempDir::Tiny;
66d02e24 10use IO::All;
5eab44a9 11
01a3246a 12my $tempdir = tempdir;
13
5eab44a9 14# set up and populate schema
01a3246a 15ok(my $schema = DBICTest->init_schema(db_dir => $tempdir), 'got schema');
5eab44a9 16
66d02e24 17my $config_dir = io->catfile(qw't var configs')->name;
5eab44a9 18
19# do dump
20ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
01a3246a 21ok($fixtures->dump({ config => 'fetch.json', schema => $schema, directory => $tempdir }), 'fetch dump executed okay');
5eab44a9 22
23# check dump is okay
01a3246a 24my $dir = dir(io->catfile($tempdir, qw'artist')->name);
5eab44a9 25my @children = $dir->children;
017d2ab4 26is(scalar(@children), 3, 'right number of artist fixtures created');
5eab44a9 27
28# check both artists dumped
29foreach 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
35my $artist1 = $schema->resultset('Artist')->find(1);
36my @artist1_cds = $artist1->cds->all;
37foreach my $cd (@artist1_cds) {
01a3246a 38 my $cd_fix_file = dir($tempdir, 'CD', $cd->id . '.fix');
5eab44a9 39 ok(-e $cd_fix_file, "artist1's cd rel dumped okay");
40}
41
42# check only cds matching artist2's cond were fetched
43my $artist2 = $schema->resultset('Artist')->find(2);
44my @artist2_cds = $artist2->cds->search({ year => { '>' => 2002 } });
45foreach my $cd (@artist2_cds) {
01a3246a 46 my $cd_fix_file = dir($tempdir, 'CD', $cd->id . '.fix');
5eab44a9 47 ok(-e $cd_fix_file, "artist2's cd rel dumped okay");
48}
49
01a3246a 50my $cd_dir = dir(io->catfile($tempdir, qw'CD')->name);
5eab44a9 51@children = $cd_dir->children;
52is(scalar(@children), scalar(@artist1_cds) + scalar(@artist2_cds), 'no extra cd fixtures dumped');
53
54
55