gitignore
[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;
66d02e24 9use IO::All;
5eab44a9 10
11# set up and populate schema
12ok(my $schema = DBICTest->init_schema(), 'got schema');
13
66d02e24 14my $config_dir = io->catfile(qw't var configs')->name;
5eab44a9 15
16# do dump
17ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
66d02e24 18ok($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 21my $dir = dir(io->catfile(qw't var fixtures artist')->name);
5eab44a9 22my @children = $dir->children;
017d2ab4 23is(scalar(@children), 3, 'right number of artist fixtures created');
5eab44a9 24
25# check both artists dumped
26foreach 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
32my $artist1 = $schema->resultset('Artist')->find(1);
33my @artist1_cds = $artist1->cds->all;
34foreach 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
40my $artist2 = $schema->resultset('Artist')->find(2);
41my @artist2_cds = $artist2->cds->search({ year => { '>' => 2002 } });
42foreach 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 47my $cd_dir = dir(io->catfile(qw't var fixtures CD')->name);
5eab44a9 48@children = $cd_dir->children;
49is(scalar(@children), scalar(@artist1_cds) + scalar(@artist2_cds), 'no extra cd fixtures dumped');
50
51
52