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