made tests cross os compatible
[dbsrgits/DBIx-Class-Fixtures.git] / t / 15-multiple-belongs-to.t
CommitLineData
610be089 1#!perl
2
3use DBIx::Class::Fixtures;
4use Test::More tests => 7;
5use lib qw(t/lib);
6use DBICTest;
7use Path::Class;
8use Data::Dumper;
66d02e24 9use IO::All;
610be089 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;
610be089 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 => 'multiple-has-many.json', schema => $schema, directory => io->catfile(qw't var fixtures')->name }), 'fetch dump executed okay');
610be089 19
20# check dump is okay
66d02e24 21my $dir = dir(io->catfile(qw't var fixtures')->name);
610be089 22
66d02e24 23ok( -e io->catfile(qw't var fixtures producer')->name, "We fetched some producers" );
24ok( -e io->catfile(qw't var fixtures cd_to_producer')->name, "We fetched some cd producer xrefs" );
25ok( -e io->catfile(qw't var fixtures CD')->name, "We fetched some cds" );
26ok( -e io->catfile(qw't var fixtures artist')->name, "We fetched some artists" );
610be089 27
28__END__
29while ( my ($dirname, $sourcename) = each %dirs ) {
30 my $this_dir = dir($dir, $dirname);
31}
32
33my $cd_dir = dir($dir, 'cd');
34my $track_dir = dir($dir, 'track');
35
36# check only artist1's cds that matched the rule were fetched
37my $artist1 = $schema->resultset('Artist')->find(1);
38my $artist1_cds = $artist1->cds;
39while (my $a1_cd = $artist1_cds->next) {
40 my $cd_fix_file = file($cd_dir, $a1_cd->id . '.fix');
41 if ($a1_cd->tags->search({ tag => 'Cheesy' })->count) {
42 ok(-e $cd_fix_file, 'cd matching rule fetched');
43 } else {
44 isnt(-e $cd_fix_file, 1, 'cd not matching rule not fetched');
45 }
46}
47
48# check only cds' tracks that matched the rule were fetched
49foreach my $cd_fix_file ($cd_dir->children) {
50 my $HASH1; eval($cd_fix_file->slurp());
51 is(ref $HASH1, 'HASH', 'cd fixture evals into hash');
52
53 my $cd = $schema->resultset('CD')->find($HASH1->{cdid});
54 foreach my $track ($cd->tracks->all) {
55 my $track_fix_file = file($track_dir, $track->id . '.fix');
56 if ($track->get_column('position') eq 2) {
57 is(-e $track_fix_file, 1, 'track matching rule fetched');
58 } else {
59 isnt(-e $track_fix_file, 1, 'track not matching rule not fetched');
60 }
61 }
62}
63