dump-basic test passes with make test
[dbsrgits/DBIx-Class-Fixtures.git] / t / 02-dump-basic.t
1 #!perl
2
3 use DBIx::Class::Fixtures;
4 use Test::More tests => 9;
5 use lib qw(t/lib);
6 use DBICTest;
7 use Path::Class;
8 use Data::Dumper; 
9
10 # set up and populate schema
11 ok(my $schema = DBICTest->init_schema(), 'got schema');
12
13 my $config_dir = 't/var/configs';
14
15 # do dump
16 ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
17 ok($fixtures->dump({ config => 'simple.json', schema => $schema, directory => 't/var/fixtures' }), 'simple dump executed okay');
18
19 # check dump is okay
20 my $dir = dir('t/var/fixtures/artist');
21 ok(-e 't/var/fixtures/artist', 'artist directory created');
22
23 my @children = $dir->children;
24 is(scalar(@children), 1, 'right number of fixtures created');
25
26 my $fix_file = $children[0];
27 my $HASH1; eval($fix_file->slurp());
28 is(ref $HASH1, 'HASH', 'fixture evals into hash');
29
30 is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys');
31
32 my $artist = $schema->resultset('Artist')->find($HASH1->{artistid});
33 is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row');
34
35 $schema->resultset('Artist')->delete; # so we can create the row again on the next line
36 ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture');