X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F96file_column.t;h=f4a166fe9db856abc78cf8dd0b543d16181805d2;hb=aac494465422ef611b92ccafffcdd426d52d8b25;hp=477386192832fe5e891ff0224ba88ecfca7200b0;hpb=28d4067a8514340167194b3397931a6cdb93be26;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/96file_column.t b/t/96file_column.t index 4773861..f4a166f 100644 --- a/t/96file_column.t +++ b/t/96file_column.t @@ -5,11 +5,81 @@ 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 => 1; +plan tests => 10; -my $fh = new IO::File('t/96file_column.t','r'); -eval { $schema->resultset('FileColumn')->create({file => {handle => $fh, filename =>'96file_column.t'}})}; -ok(!$@,'FileColumn checking if file handled properly.'); +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' ); + +$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' ); + +$fh = $source_file->openr or die "failed to open $source_file: $!\n"; +$fc = $rs->create({ file => { handle => $fh, filename => $fname } }); + +# read it back +$fc->discard_changes; + +$storage = file( + $fc->column_info('file')->{file_column_path}, + $fc->id, + $fc->file->{filename}, +); + +TODO: { + local $TODO = 'need resultset delete override to delete_all'; + $rs->delete; + ok ( ! -e $storage, 'storage does not exist after $rs->delete' ); +};