switch tests to Test::TempDir::Tiny to enable parallelization
[dbsrgits/DBIx-Class-Fixtures.git] / t / 16-rules-hasmany.t
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;
9 use Test::TempDir::Tiny;
10 use IO::All;
11
12 my $tempdir = tempdir;
13
14 # set up and populate schema
15 ok(my $schema = DBICTest->init_schema(db_dir => $tempdir), 'got schema');
16
17 my $config_dir = io->catfile(qw't var configs')->name;
18
19 # do dump
20 ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
21 ok($fixtures->dump({ config => 'rules2.json', schema => $schema, directory => $tempdir }), 'quantity dump executed okay');
22
23 # check dump is okay
24 foreach my $test (
25   [ 'artist', 1, 'Artist', 'artistid' ],
26   [ 'CD', 2, 'CD', 'cdid' ],
27 ) {
28   my ($dirname, $count, $moniker, $id) = @$test;
29   my $dir = dir(io->catfile($tempdir,$dirname)->name);
30   my @children = $dir->children;
31   is(scalar(@children), $count, "right number of $dirname fixtures created");
32
33   foreach my $fix_file (@children) {
34     my $HASH1; eval($fix_file->slurp());
35     is(ref $HASH1, 'HASH', 'fixture evals into hash');
36     my $obj = $schema->resultset($moniker)->find($HASH1->{$id});
37     is_deeply({$obj->get_columns}, $HASH1, "dumped fixture is equivalent to $dirname row");
38   }
39 }
40