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({ |
3d4debec |
21 | album=> {name=>'masterpiece'}, |
22 | photographer=> {name=>'john'}, |
6d01d9c1 |
23 | file=>$fh, |
24 | }); |
25 | |
26 | close($fh); |
27 | |
28 | my $fixtures = DBIx::Class::Fixtures |
29 | ->new({ |
66d02e24 |
30 | config_dir => io->catfile(qw't var configs')->name, |
31 | config_attrs => { photo_dir => io->catfile(qw't var files')->name }, |
6d01d9c1 |
32 | debug => 0 }); |
33 | |
34 | ok( |
35 | $fixtures->dump({ |
36 | config => 'extra.json', |
37 | schema => $schema, |
01a3246a |
38 | directory => io->catfile($tempdir, qw" photos")->name }), |
6d01d9c1 |
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; |
3d4debec |
46 | ok $schema->resultset('Photographer')->delete; |
47 | ok $schema->resultset('Album')->delete; |
6d01d9c1 |
48 | |
49 | ok ! -e $key, 'File Deleted'; |
50 | |
51 | ok( |
52 | $fixtures->populate({ |
53 | no_deploy => 1, |
54 | schema => $schema, |
01a3246a |
55 | directory => io->catfile($tempdir, qw" photos")->name}), |
6d01d9c1 |
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 { |
66d02e24 |
66 | rmtree io->catfile(qw't var files')->name; |
01a3246a |
67 | rmtree io->catfile($tempdir, qw'photos')->name; |
6d01d9c1 |
68 | } |