3 use DBIx::Class::Fixtures;
4 use Test::More tests => 17;
11 use if $^O eq 'MSWin32','Devel::Confess';
12 # set up and populate schema
13 ok(my $schema = DBICTest->init_schema(), 'got schema');
15 my $config_dir = io->catfile(qw't var configs')->name;
19 ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
20 ok($fixtures->dump({ config => 'simple.json', schema => $schema, directory => io->catfile(qw't var fixtures')->name }), 'simple dump executed okay');
23 my $dir = dir(io->catfile(qw't var fixtures artist')->name);
24 ok(-e io->catfile(qw't var fixtures artist')->name, 'artist directory created');
26 my @children = $dir->children;
27 is(scalar(@children), 1, 'right number of fixtures created');
29 my $fix_file = $children[0];
30 my $HASH1; eval($fix_file->slurp());
31 is(ref $HASH1, 'HASH', 'fixture evals into hash');
33 is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys');
35 my $artist = $schema->resultset('Artist')->find($HASH1->{artistid});
36 is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row');
38 $schema->resultset('Artist')->delete; # so we can create the row again on the next line
39 ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture');
43 # do dump with hashref config
44 ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
59 directory => io->catfile(qw't var fixtures')->name,
60 }), 'simple dump executed okay');
63 my $dir = dir(io->catfile(qw't var fixtures artist')->name);
64 ok(-e io->catfile(qw't var fixtures artist')->name, 'artist directory created');
66 my @children = $dir->children;
67 is(scalar(@children), 1, 'right number of fixtures created');
69 my $fix_file = $children[0];
70 my $HASH1; eval($fix_file->slurp());
71 is(ref $HASH1, 'HASH', 'fixture evals into hash');
73 is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys');
75 my $artist = $schema->resultset('Artist')->find($HASH1->{artistid});
76 is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row');
78 $schema->resultset('Artist')->delete; # so we can create the row again on the next line
79 ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture');