changelog
[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     album=> {name=>'masterpiece'},
22     photographer=> {name=>'john'},
23     file=>$fh,
24   });
25
26 close($fh);
27
28 my $fixtures = DBIx::Class::Fixtures
29   ->new({
30     config_dir => io->catfile(qw't var configs')->name,
31     config_attrs => { photo_dir => io->catfile(qw't var files')->name },
32     debug => 0 });
33
34 ok(
35   $fixtures->dump({
36     config => 'extra.json',
37     schema => $schema,
38     directory => io->catfile($tempdir, qw" photos")->name }),
39   'fetch dump executed okay');
40
41 ok my $key = $schema->resultset('Photo')->first->file;
42
43 ok -e $key, 'File Created';
44
45 ok $schema->resultset('Photo')->delete;
46 ok $schema->resultset('Photographer')->delete;
47 ok $schema->resultset('Album')->delete;
48
49 ok ! -e $key, 'File Deleted';
50
51 ok(
52   $fixtures->populate({
53     no_deploy => 1,
54     schema => $schema,
55     directory => io->catfile($tempdir, qw" photos")->name}),
56   'populated');
57
58 is $key, $schema->resultset('Photo')->first->file,
59   'key is key';
60
61 ok -e $key, 'File Restored';
62
63 done_testing;
64
65 END {
66     rmtree io->catfile(qw't var files')->name;
67     rmtree io->catfile($tempdir, qw'photos')->name;
68 }