75528d57f2e407292a2c8917d1cd7f65c22e0977
[dbsrgits/DBIx-Class-Fixtures.git] / t / 18-extra.t
1 use DBIx::Class::Fixtures;
2 use Test::More;
3 use File::Path 'rmtree';
4
5 use lib qw(t/lib);
6 use ExtraTest::Schema;
7 use Test::TempDir::Tiny;
8 use IO::All;
9
10 my $tempdir = tempdir;
11
12 (my $schema = ExtraTest::Schema->connect(
13   'DBI:SQLite::memory:','',''))->init_schema;
14
15 open(my $fh, '<', io->catfile(qw't 18-extra.t')->name) ||
16   die "Can't open the filehandle, test is trash!";
17
18 ok my $row = $schema
19   ->resultset('Photo')
20   ->create({
21     photographer=>'john',
22     file=>$fh,
23   });
24
25 close($fh);
26
27 my $fixtures = DBIx::Class::Fixtures
28   ->new({
29     config_dir => io->catfile(qw't var configs')->name,
30     config_attrs => { photo_dir => io->catfile(qw't var files')->name },
31     debug => 0 });
32
33 ok(
34   $fixtures->dump({
35     config => 'extra.json',
36     schema => $schema,
37     directory => io->catfile($tempdir, qw" photos")->name }),
38   'fetch dump executed okay');
39
40 ok my $key = $schema->resultset('Photo')->first->file;
41
42 ok -e $key, 'File Created';
43
44 ok $schema->resultset('Photo')->delete;
45
46 ok ! -e $key, 'File Deleted';
47
48 ok(
49   $fixtures->populate({
50     no_deploy => 1,
51     schema => $schema,
52     directory => io->catfile($tempdir, qw" photos")->name}),
53   'populated');
54
55 is $key, $schema->resultset('Photo')->first->file,
56   'key is key';
57
58 ok -e $key, 'File Restored';
59
60 done_testing;
61
62 END {
63     rmtree io->catfile(qw't var files')->name;
64     rmtree io->catfile($tempdir, qw'photos')->name;
65 }