1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!perl
use strict;
use warnings;
use Test::More tests => 5;
use Path::Class::File;
use Path::Class::Dir;
use lib qw(t/lib);
use DBICx::TestDatabase;
use IO::File;
my $schema = DBICx::TestDatabase->new('My::TestSchema');
my $rs = $schema->resultset('Book');
# we'll use *this* file as our content
# TODO: Copy it or create something else so errant tests don't inadvertently
# delete it!
my $book = $rs->create({
name => 'Alice in Wonderland',
});
my $base = $book->column_info('cover_image_2')->{fs_column_path};
my $fh = new IO::File "t/var/testfile.txt";
$book->cover_image_2($fh);
$book->update;
my $name;
like($name = $book->cover_image_2, qr{^\Q$base\E});
$fh = new IO::File "t/var/testfile.txt";
$book->cover_image_2($fh);
$book->update;
ok(!-e $name, "old file does not exist anymore");
like($name = $book->cover_image_2, qr{^\Q$base\E});
ok(-e $name);
$book = $schema->resultset("Book")->first;
is($book->cover_image_2, $name, "name did not change on retrieve");
|