Created
April 12, 2011 20:51
-
-
Save semifor/916379 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!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