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