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