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