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; |
66d02e24 |
7 | use IO::All; |
6d01d9c1 |
8 | |
9 | (my $schema = ExtraTest::Schema->connect( |
10 | 'DBI:SQLite::memory:','',''))->init_schema; |
11 | |
66d02e24 |
12 | open(my $fh, '<', io->catfile(qw't 18-extra.t')->name) || |
6d01d9c1 |
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({ |
66d02e24 |
26 | config_dir => io->catfile(qw't var configs')->name, |
27 | config_attrs => { photo_dir => io->catfile(qw't var files')->name }, |
6d01d9c1 |
28 | debug => 0 }); |
29 | |
30 | ok( |
31 | $fixtures->dump({ |
32 | config => 'extra.json', |
33 | schema => $schema, |
66d02e24 |
34 | directory => io->catfile(qw"t var fixtures photos")->name }), |
6d01d9c1 |
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, |
66d02e24 |
49 | directory => io->catfile(qw"t var fixtures photos")->name}), |
6d01d9c1 |
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 { |
66d02e24 |
60 | rmtree io->catfile(qw't var files')->name; |
61 | rmtree io->catfile(qw't var fixtures photos')->name; |
6d01d9c1 |
62 | } |