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; |
01a3246a |
9 | use Test::TempDir::Tiny; |
66d02e24 |
10 | use IO::All; |
5eab44a9 |
11 | |
01a3246a |
12 | my $tempdir = tempdir; |
13 | |
5eab44a9 |
14 | # set up and populate schema |
01a3246a |
15 | ok(my $schema = DBICTest->init_schema(db_dir => $tempdir), 'got schema'); |
5eab44a9 |
16 | |
66d02e24 |
17 | my $config_dir = io->catfile(qw't var configs')->name; |
5eab44a9 |
18 | |
19 | # do dump |
20 | ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); |
01a3246a |
21 | ok($fixtures->dump({ config => 'fetch.json', schema => $schema, directory => $tempdir }), 'fetch dump executed okay'); |
5eab44a9 |
22 | |
23 | # check dump is okay |
01a3246a |
24 | my $dir = dir(io->catfile($tempdir, qw'artist')->name); |
5eab44a9 |
25 | my @children = $dir->children; |
017d2ab4 |
26 | is(scalar(@children), 3, 'right number of artist fixtures created'); |
5eab44a9 |
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) { |
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 |
43 | my $artist2 = $schema->resultset('Artist')->find(2); |
44 | my @artist2_cds = $artist2->cds->search({ year => { '>' => 2002 } }); |
45 | foreach 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 |
50 | my $cd_dir = dir(io->catfile($tempdir, qw'CD')->name); |
5eab44a9 |
51 | @children = $cd_dir->children; |
52 | is(scalar(@children), scalar(@artist1_cds) + scalar(@artist2_cds), 'no extra cd fixtures dumped'); |
53 | |
54 | |
55 | |