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