1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
12 use Path::Class qw/file/;
15 local $ENV{DBIC_IC_FILE_NOWARN} = 1;
17 package DBICTest::Schema::FileColumn;
21 use base qw/DBICTest::BaseResult/;
23 __PACKAGE__->load_components (qw/InflateColumn::File/);
24 __PACKAGE__->table('file_columns');
26 __PACKAGE__->add_columns(
27 id => { data_type => 'integer', is_auto_increment => 1 },
29 data_type => 'varchar',
31 file_column_path => File::Temp->newdir( CLEANUP => 1, DIR => DBICTest::Util::tmpdir() ),
36 __PACKAGE__->set_primary_key('id');
38 DBICTest::Schema->load_classes('FileColumn');
40 my $schema = DBICTest->init_schema;
44 if (not $ENV{DBICTEST_SQLT_DEPLOY}) {
45 $schema->storage->dbh->do(<<'EOF');
46 CREATE TABLE file_columns (
47 id INTEGER PRIMARY KEY,
53 my $rs = $schema->resultset('FileColumn');
54 my $source_file = file(__FILE__);
55 my $fname = $source_file->basename;
56 my $fh = $source_file->open('r') or die "failed to open $source_file: $!\n";
58 $rs->create({ file => { handle => $fh, filename => $fname } })
60 is ( $@, '', 'created' );
65 $fc->column_info('file')->{file_column_path},
67 $fc->file->{filename},
69 ok ( -e $storage, 'storage exists' );
72 $fc = $rs->find({ id => $fc->id });
74 is ( $fc->file->{filename}, $fname, 'filename matches' );
75 ok ( compare($storage, $source_file) == 0, 'file contents matches' );
78 my $new_fname = 'File.pm';
79 my $new_source_file = file(qw/lib DBIx Class InflateColumn File.pm/);
80 my $new_storage = file(
81 $fc->column_info('file')->{file_column_path},
85 $fh = $new_source_file->open('r') or die "failed to open $new_source_file: $!\n";
87 $fc->file({ handle => $fh, filename => $new_fname });
91 local $TODO = 'design change required';
92 ok ( ! -e $storage, 'old storage does not exist' );
95 ok ( -e $new_storage, 'new storage exists' );
98 $fc = $rs->find({ id => $fc->id });
100 is ( $fc->file->{filename}, $new_fname, 'new filname matches' );
101 ok ( compare($new_storage, $new_source_file) == 0, 'new content matches' );
103 if ($^O eq 'MSWin32') {
104 close $fc->file->{handle}; # can't delete open files on Win32
108 ok ( ! -e $storage, 'storage deleted' );
110 $fh = $source_file->openr or die "failed to open $source_file: $!\n";
111 $fc = $rs->create({ file => { handle => $fh, filename => $fname } });
114 $fc->discard_changes;
117 $fc->column_info('file')->{file_column_path},
119 $fc->file->{filename},
123 local $TODO = 'need resultset delete override to delete_all';
125 ok ( ! -e $storage, 'storage does not exist after $rs->delete' );