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