changelog
[dbsrgits/DBIx-Class-Fixtures.git] / t / 17-dump_all_config_sets.t
CommitLineData
5cc47846 1use DBIx::Class::Fixtures;
281f2645 2use Test::More tests => 9;
5cc47846 3
4use lib qw(t/lib);
5use DBICTest;
6use Path::Class;
7use Data::Dumper;
8use File::Spec;
9
10ok my $config_dir = 't/var/configs';
11ok my $schema = DBICTest->init_schema(), 'got schema';
12ok my $fixtures = DBIx::Class::Fixtures->new({config_dir => $config_dir}),
13 'object created with correct config dir';
14
281f2645 15
16my $ret = $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
25ok -e 't/var/fixtures/multi/date.json/artist',
26 'artist directory created';
27
28my $dir = dir('t/var/fixtures/multi/date.json/artist');
29my @children = $dir->children;
30is(scalar(@children), 1, 'right number of fixtures created');
31
32my $fix_file = $children[0];
33my $HASH1; eval($fix_file->slurp());
34is(ref $HASH1, 'HASH', 'fixture evals into hash');
35
36is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys');
37
38my $artist = $schema->resultset('Artist')->find($HASH1->{artistid});
39is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row');
40
41$schema->resultset('Artist')->delete; # so we can create the row again on the next line
42 ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture');
43
5cc47846 44
45