made tests cross os compatible
[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 IO::All;
10
11 # set up and populate schema
12 ok(my $schema = DBICTest->init_schema(), 'got schema');
13
14 my $config_dir = io->catfile(qw't var configs')->name;
15
16 # do dump
17 ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
18 ok($fixtures->dump({ config => 'fetch.json', schema => $schema, directory => io->catfile(qw't var fixtures')->name }), 'fetch dump executed okay');
19
20 # check dump is okay
21 my $dir = dir(io->catfile(qw't var fixtures artist')->name);
22 my @children = $dir->children;
23 is(scalar(@children), 3, 'right number of artist fixtures created');
24
25 # check both artists dumped
26 foreach my $id (1, 2) {
27   my $artist_fix_file = dir($dir, $id . '.fix');
28   ok(-e $artist_fix_file, "artist $id dumped okay");
29 }
30
31 # check all of artist1's cds were fetched
32 my $artist1 = $schema->resultset('Artist')->find(1);
33 my @artist1_cds = $artist1->cds->all;
34 foreach my $cd (@artist1_cds) {
35   my $cd_fix_file = dir(io->catfile(qw't var fixtures')->name, 'CD', $cd->id . '.fix');
36   ok(-e $cd_fix_file, "artist1's cd rel dumped okay");
37 }
38
39 # check only cds matching artist2's cond were fetched
40 my $artist2 = $schema->resultset('Artist')->find(2);
41 my @artist2_cds = $artist2->cds->search({ year => { '>' => 2002 } });
42 foreach my $cd (@artist2_cds) {
43   my $cd_fix_file = dir(io->catfile(qw't var fixtures')->name, 'CD', $cd->id . '.fix');
44   ok(-e $cd_fix_file, "artist2's cd rel dumped okay");
45 }
46
47 my $cd_dir = dir(io->catfile(qw't var fixtures CD')->name);
48 @children = $cd_dir->children;
49 is(scalar(@children), scalar(@artist1_cds) + scalar(@artist2_cds), 'no extra cd fixtures dumped');
50
51
52