Commit | Line | Data |
4740bdb7 |
1 | use strict; |
3814fdad |
2 | use warnings; |
4740bdb7 |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
823c91a1 |
6 | |
7 | # inject IC::File into the result baseclass for testing |
8 | BEGIN { |
9 | $ENV{DBIC_IC_FILE_NOWARN} = 1; |
10 | require DBICTest::BaseResult; |
11 | DBICTest::BaseResult->load_components (qw/InflateColumn::File/); |
12 | } |
13 | |
14 | |
4740bdb7 |
15 | use DBICTest; |
26ddc864 |
16 | use File::Compare; |
17 | use Path::Class qw/file/; |
4740bdb7 |
18 | |
823c91a1 |
19 | my $schema = DBICTest->init_schema; |
4740bdb7 |
20 | |
5d8d8611 |
21 | plan tests => 10; |
4740bdb7 |
22 | |
26ddc864 |
23 | my $rs = $schema->resultset('FileColumn'); |
100fd57f |
24 | my $source_file = file(__FILE__); |
25 | my $fname = $source_file->basename; |
26ddc864 |
26 | my $fh = $source_file->open('r') or die "failed to open $source_file: $!\n"; |
27 | my $fc = eval { |
28 | $rs->create({ file => { handle => $fh, filename => $fname } }) |
29 | }; |
30 | is ( $@, '', 'created' ); |
31 | |
32 | $fh->close; |
33 | |
34 | my $storage = file( |
35 | $fc->column_info('file')->{file_column_path}, |
36 | $fc->id, |
37 | $fc->file->{filename}, |
38 | ); |
39 | ok ( -e $storage, 'storage exists' ); |
40 | |
41 | # read it back |
42 | $fc = $rs->find({ id => $fc->id }); |
43 | |
44 | is ( $fc->file->{filename}, $fname, 'filename matches' ); |
45 | ok ( compare($storage, $source_file) == 0, 'file contents matches' ); |
46 | |
47 | # update |
48 | my $new_fname = 'File.pm'; |
49 | my $new_source_file = file(qw/lib DBIx Class InflateColumn File.pm/); |
50 | my $new_storage = file( |
51 | $fc->column_info('file')->{file_column_path}, |
52 | $fc->id, |
53 | $new_fname, |
54 | ); |
55 | $fh = $new_source_file->open('r') or die "failed to open $new_source_file: $!\n"; |
56 | |
57 | $fc->file({ handle => $fh, filename => $new_fname }); |
58 | $fc->update; |
59 | |
60 | TODO: { |
61 | local $TODO = 'design change required'; |
62 | ok ( ! -e $storage, 'old storage does not exist' ); |
63 | }; |
64 | |
65 | ok ( -e $new_storage, 'new storage exists' ); |
66 | |
67 | # read it back |
68 | $fc = $rs->find({ id => $fc->id }); |
69 | |
70 | is ( $fc->file->{filename}, $new_fname, 'new filname matches' ); |
71 | ok ( compare($new_storage, $new_source_file) == 0, 'new content matches' ); |
72 | |
73 | $fc->delete; |
74 | |
75 | ok ( ! -e $storage, 'storage deleted' ); |
30a93e27 |
76 | |
5d8d8611 |
77 | $fh = $source_file->openr or die "failed to open $source_file: $!\n"; |
78 | $fc = $rs->create({ file => { handle => $fh, filename => $fname } }); |
30a93e27 |
79 | |
5d8d8611 |
80 | # read it back |
81 | $fc->discard_changes; |
30a93e27 |
82 | |
5d8d8611 |
83 | $storage = file( |
84 | $fc->column_info('file')->{file_column_path}, |
85 | $fc->id, |
86 | $fc->file->{filename}, |
87 | ); |
30a93e27 |
88 | |
5d8d8611 |
89 | TODO: { |
90 | local $TODO = 'need resultset delete override to delete_all'; |
30a93e27 |
91 | $rs->delete; |
92 | ok ( ! -e $storage, 'storage does not exist after $rs->delete' ); |
93 | }; |