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