3 use DBIx::Class::Fixtures;
4 use Test::More tests => 17;
9 use Test::TempDir::Tiny;
12 my $tempdir = tempdir;
14 use if $^O eq 'MSWin32','Devel::Confess';
15 # set up and populate schema
16 ok(my $schema = DBICTest->init_schema(db_dir => $tempdir), 'got schema');
18 my $config_dir = io->catfile(qw't var configs')->name;
22 ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
23 ok($fixtures->dump({ config => 'simple.json', schema => $schema, directory => $tempdir }), 'simple dump executed okay');
26 my $dir = dir(io->catfile($tempdir, qw'artist')->name);
27 ok(-e io->catfile($tempdir, qw'artist')->name, 'artist directory created');
29 my @children = $dir->children;
30 is(scalar(@children), 1, 'right number of fixtures created');
32 my $fix_file = $children[0];
33 my $HASH1; eval($fix_file->slurp());
34 is(ref $HASH1, 'HASH', 'fixture evals into hash');
36 is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys');
38 my $artist = $schema->resultset('Artist')->find($HASH1->{artistid});
39 is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row');
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');
46 # do dump with hashref config
47 ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
62 directory => $tempdir,
63 }), 'simple dump executed okay');
66 my $dir = dir(io->catfile($tempdir, qw'artist')->name);
67 ok(-e io->catfile($tempdir, qw'artist')->name, 'artist directory created');
69 my @children = $dir->children;
70 is(scalar(@children), 1, 'right number of fixtures created');
72 my $fix_file = $children[0];
73 my $HASH1; eval($fix_file->slurp());
74 is(ref $HASH1, 'HASH', 'fixture evals into hash');
76 is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys');
78 my $artist = $schema->resultset('Artist')->find($HASH1->{artistid});
79 is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row');
81 $schema->resultset('Artist')->delete; # so we can create the row again on the next line
82 ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture');