Skip to content

Instantly share code, notes, and snippets.

@semifor
Created April 12, 2011 20:51
Show Gist options
  • Select an option

  • Save semifor/916379 to your computer and use it in GitHub Desktop.

Select an option

Save semifor/916379 to your computer and use it in GitHub Desktop.
#!perl
use warnings;
use strict;
use DBICx::TestDatabase;
use Test::More tests => 3;
use Path::Class qw/file/;
use File::Find;
use lib qw(t/lib);
my $schema = DBICx::TestDatabase->new('My::TestSchema');
# we'll use *this* file as our content
# TODO: Copy it or create something else so errant tests don't inadvertently
# delete it!
my $file = file($0);
$schema->txn_do(sub {
my $author = $schema->resultset('Author')->create({
name => 'Joseph Heller',
books => [
{ name => 'Catch 22', cover_image => $file },
{ name => 'Something Happened', cover_image => $file },
],
});
is ( $author->books->count, 2, 'created 2 books' );
});
ok $schema->resultset('Book')->find({ name => 'Catch 22' }), 'exists after transaction';
{
my $storage_dir = $schema->resultset('Book')
->result_source
->column_info('cover_image')
->{fs_column_path};
my $file_count = 0;
find(sub { -f && ++$file_count }, $storage_dir);
is ( $file_count, 2, '2 backing files' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment