new config option to DBICTest to let you set an alternative storage type, start on...
[dbsrgits/DBIx-Class.git] / t / 96file_column.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7 use IO::File;
8 use File::Compare;
9 use Path::Class qw/file/;
10
11 my $schema = DBICTest->init_schema();
12
13 plan tests => 9;
14
15 my $rs = $schema->resultset('FileColumn');
16 my $fname = '96file_column.t';
17 my $source_file = file('t', $fname);
18 my $fh = $source_file->open('r') or die "failed to open $source_file: $!\n";
19 my $fc = eval {
20     $rs->create({ file => { handle => $fh, filename => $fname } })
21 };
22 is ( $@, '', 'created' );
23
24 $fh->close;
25
26 my $storage = file(
27     $fc->column_info('file')->{file_column_path},
28     $fc->id,
29     $fc->file->{filename},
30 );
31 ok ( -e $storage, 'storage exists' );
32
33 # read it back
34 $fc = $rs->find({ id => $fc->id });
35
36 is ( $fc->file->{filename}, $fname, 'filename matches' );
37 ok ( compare($storage, $source_file) == 0, 'file contents matches' );
38
39 # update
40 my $new_fname = 'File.pm';
41 my $new_source_file = file(qw/lib DBIx Class InflateColumn File.pm/);
42 my $new_storage = file(
43     $fc->column_info('file')->{file_column_path},
44     $fc->id,
45     $new_fname,
46 );
47 $fh = $new_source_file->open('r') or die "failed to open $new_source_file: $!\n";
48
49 $fc->file({ handle => $fh, filename => $new_fname });
50 $fc->update;
51
52 TODO: {
53     local $TODO = 'design change required';
54     ok ( ! -e $storage, 'old storage does not exist' );
55 };
56
57 ok ( -e $new_storage, 'new storage exists' );
58
59 # read it back
60 $fc = $rs->find({ id => $fc->id });
61
62 is ( $fc->file->{filename}, $new_fname, 'new filname matches' );
63 ok ( compare($new_storage, $new_source_file) == 0, 'new content matches' );
64
65 $fc->delete;
66
67 ok ( ! -e $storage, 'storage deleted' );