Commit | Line | Data |
5eab44a9 |
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; |
66d02e24 |
9 | use IO::All; |
5eab44a9 |
10 | |
11 | # set up and populate schema |
12 | ok(my $schema = DBICTest->init_schema(), 'got schema'); |
13 | |
66d02e24 |
14 | my $config_dir = io->catfile(qw't var configs')->name; |
5eab44a9 |
15 | |
16 | # do dump |
17 | ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); |
66d02e24 |
18 | ok($fixtures->dump({ config => 'fetch.json', schema => $schema, directory => io->catfile(qw't var fixtures')->name }), 'fetch dump executed okay'); |
5eab44a9 |
19 | |
20 | # check dump is okay |
66d02e24 |
21 | my $dir = dir(io->catfile(qw't var fixtures artist')->name); |
5eab44a9 |
22 | my @children = $dir->children; |
017d2ab4 |
23 | is(scalar(@children), 3, 'right number of artist fixtures created'); |
5eab44a9 |
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) { |
66d02e24 |
35 | my $cd_fix_file = dir(io->catfile(qw't var fixtures')->name, 'CD', $cd->id . '.fix'); |
5eab44a9 |
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) { |
66d02e24 |
43 | my $cd_fix_file = dir(io->catfile(qw't var fixtures')->name, 'CD', $cd->id . '.fix'); |
5eab44a9 |
44 | ok(-e $cd_fix_file, "artist2's cd rel dumped okay"); |
45 | } |
46 | |
66d02e24 |
47 | my $cd_dir = dir(io->catfile(qw't var fixtures CD')->name); |
5eab44a9 |
48 | @children = $cd_dir->children; |
49 | is(scalar(@children), scalar(@artist1_cds) + scalar(@artist2_cds), 'no extra cd fixtures dumped'); |
50 | |
51 | |
52 | |