X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F96file_column.t;h=d1984254c59a9bc2187a3c866dd48e157206e980;hb=a778f387401f12b9823aeab5afd200b3623d31a8;hp=25d914923f2ac4e6df62f2c872ffda7e536be566;hpb=d4391b185237f3fc856805a699fb2cef993bcaad;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/96file_column.t b/t/96file_column.t index 25d9149..d198425 100644 --- a/t/96file_column.t +++ b/t/96file_column.t @@ -5,14 +5,63 @@ use Test::More; use lib qw(t/lib); use DBICTest; use IO::File; +use File::Compare; +use Path::Class qw/file/; my $schema = DBICTest->init_schema(); -plan tests => 2; +plan tests => 9; +my $rs = $schema->resultset('FileColumn'); +my $fname = '96file_column.t'; +my $source_file = file('t', $fname); +my $fh = $source_file->open('r') or die "failed to open $source_file: $!\n"; +my $fc = eval { + $rs->create({ file => { handle => $fh, filename => $fname } }) +}; +is ( $@, '', 'created' ); -eval { $schema->resultset('FileColumn')->create({file=>'wrong set'}) }; -ok($@, 'FileColumn checking for checks against bad sets'); -my $fh = new IO::File('t/96file_column.pm','r'); -eval { $schema->resultset('FileColumn')->create({file => {handle => $fh, filename =>'96file_column.pm'}})}; -ok(!$@,'FileColumn checking if file handled properly.'); +$fh->close; + +my $storage = file( + $fc->column_info('file')->{file_column_path}, + $fc->id, + $fc->file->{filename}, +); +ok ( -e $storage, 'storage exists' ); + +# read it back +$fc = $rs->find({ id => $fc->id }); + +is ( $fc->file->{filename}, $fname, 'filename matches' ); +ok ( compare($storage, $source_file) == 0, 'file contents matches' ); + +# update +my $new_fname = 'File.pm'; +my $new_source_file = file(qw/lib DBIx Class InflateColumn File.pm/); +my $new_storage = file( + $fc->column_info('file')->{file_column_path}, + $fc->id, + $new_fname, +); +$fh = $new_source_file->open('r') or die "failed to open $new_source_file: $!\n"; + +$fc->file({ handle => $fh, filename => $new_fname }); +$fc->update; + +TODO: { + local $TODO = 'design change required'; + ok ( ! -e $storage, 'old storage does not exist' ); +}; + +ok ( -e $new_storage, 'new storage exists' ); + +# read it back +$fc = $rs->find({ id => $fc->id }); + +is ( $fc->file->{filename}, $new_fname, 'new filname matches' ); +ok ( compare($new_storage, $new_source_file) == 0, 'new content matches' ); + +$fc->delete; + +ok ( ! -e $storage, 'storage deleted' );