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