Commit | Line | Data |
06b7a1cc |
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; |
06b7a1cc |
11 | |
01a3246a |
12 | my $tempdir = tempdir; |
13 | |
06b7a1cc |
14 | # set up and populate schema |
01a3246a |
15 | ok(my $schema = DBICTest->init_schema(db_dir => $tempdir), 'got schema'); |
06b7a1cc |
16 | |
66d02e24 |
17 | my $config_dir = io->catfile(qw't var configs')->name; |
06b7a1cc |
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 => 'rules2.json', schema => $schema, directory => $tempdir }), 'quantity dump executed okay'); |
06b7a1cc |
22 | |
23 | # check dump is okay |
24 | foreach my $test ( |
25 | [ 'artist', 1, 'Artist', 'artistid' ], |
dcdf675f |
26 | [ 'CD', 2, 'CD', 'cdid' ], |
06b7a1cc |
27 | ) { |
28 | my ($dirname, $count, $moniker, $id) = @$test; |
01a3246a |
29 | my $dir = dir(io->catfile($tempdir,$dirname)->name); |
06b7a1cc |
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 | |