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