Commit | Line | Data |
6d01d9c1 |
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; |
01a3246a |
7 | use Test::TempDir::Tiny; |
66d02e24 |
8 | use IO::All; |
6d01d9c1 |
9 | |
01a3246a |
10 | my $tempdir = tempdir; |
11 | |
6d01d9c1 |
12 | (my $schema = ExtraTest::Schema->connect( |
13 | 'DBI:SQLite::memory:','',''))->init_schema; |
14 | |
66d02e24 |
15 | open(my $fh, '<', io->catfile(qw't 18-extra.t')->name) || |
6d01d9c1 |
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({ |
66d02e24 |
29 | config_dir => io->catfile(qw't var configs')->name, |
30 | config_attrs => { photo_dir => io->catfile(qw't var files')->name }, |
6d01d9c1 |
31 | debug => 0 }); |
32 | |
33 | ok( |
34 | $fixtures->dump({ |
35 | config => 'extra.json', |
36 | schema => $schema, |
01a3246a |
37 | directory => io->catfile($tempdir, qw" photos")->name }), |
6d01d9c1 |
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, |
01a3246a |
52 | directory => io->catfile($tempdir, qw" photos")->name}), |
6d01d9c1 |
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 { |
66d02e24 |
63 | rmtree io->catfile(qw't var files')->name; |
01a3246a |
64 | rmtree io->catfile($tempdir, qw'photos')->name; |
6d01d9c1 |
65 | } |