f150caca6f5e7715e3016111360bf476c56cf94f
[dbsrgits/DBIx-Class-Fixtures.git] / t / 17-dump_all_config_sets.t
1 use DBIx::Class::Fixtures;
2 use Test::More tests => 17;
3
4 use lib qw(t/lib);
5 use DBICTest;
6 use Path::Class;
7 use Data::Dumper; 
8 use File::Spec;
9
10 ok my $config_dir = 't/var/configs';
11 ok my $schema = DBICTest->init_schema(), 'got schema';
12 ok my $fixtures = DBIx::Class::Fixtures->new({config_dir => $config_dir}),
13   'object created with correct config dir';
14   
15 ok(
16   $fixtures->dump_config_sets({
17     configs => [qw/date.json rules.json/],
18     schema => $schema,
19     directory_template => sub {
20         my ($fixture, $params, $set) = @_;
21         File::Spec->catdir('t','var','fixtures','multi', $set);
22     },
23   }),
24   'simple dump executed okay',
25 );
26
27 __END__
28
29     # check dump is okay
30     my $dir = dir('t/var/fixtures/artist');
31     ok(-e 't/var/fixtures/artist', 'artist directory created');
32
33     my @children = $dir->children;
34     is(scalar(@children), 1, 'right number of fixtures created');
35
36     my $fix_file = $children[0];
37     my $HASH1; eval($fix_file->slurp());
38     is(ref $HASH1, 'HASH', 'fixture evals into hash');
39
40     is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys');
41
42     my $artist = $schema->resultset('Artist')->find($HASH1->{artistid});
43     is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row');
44
45     $schema->resultset('Artist')->delete; # so we can create the row again on the next line
46     ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture');
47 }
48
49