[Bast-commits] r9584 - in DBIx-Class-InflateColumn-FS/1.000/trunk: . lib/DBIx/Class/InflateColumn t

semifor at dev.catalyst.perl.org semifor at dev.catalyst.perl.org
Tue Jun 22 16:49:42 GMT 2010


Author: semifor
Date: 2010-06-22 17:49:42 +0100 (Tue, 22 Jun 2010)
New Revision: 9584

Added:
   DBIx-Class-InflateColumn-FS/1.000/trunk/t/10-result_set.t
Modified:
   DBIx-Class-InflateColumn-FS/1.000/trunk/Changes
   DBIx-Class-InflateColumn-FS/1.000/trunk/README
   DBIx-Class-InflateColumn-FS/1.000/trunk/lib/DBIx/Class/InflateColumn/FS.pm
   DBIx-Class-InflateColumn-FS/1.000/trunk/t/01-fs_columns.t
   DBIx-Class-InflateColumn-FS/1.000/trunk/t/99-pod_spelling.t
Log:
Bug fix: ensure fs columns are marked dirty when set via accessors

Modified: DBIx-Class-InflateColumn-FS/1.000/trunk/Changes
===================================================================
--- DBIx-Class-InflateColumn-FS/1.000/trunk/Changes	2010-06-08 12:42:56 UTC (rev 9583)
+++ DBIx-Class-InflateColumn-FS/1.000/trunk/Changes	2010-06-22 16:49:42 UTC (rev 9584)
@@ -1,3 +1,6 @@
+0.01007 2010-06-22
+    - Bug fix: ensure fs columns are marked dirty when set via accessors
+
 0.01006 2010-05-28
     - Added DESTROY to delete file backing for un-inserted rows
     - Added TODO tests for multi-create failure pending DBIx::Class::Row patch

Modified: DBIx-Class-InflateColumn-FS/1.000/trunk/README
===================================================================
--- DBIx-Class-InflateColumn-FS/1.000/trunk/README	2010-06-08 12:42:56 UTC (rev 9583)
+++ DBIx-Class-InflateColumn-FS/1.000/trunk/README	2010-06-22 16:49:42 UTC (rev 9584)
@@ -95,6 +95,13 @@
 AUTHOR
     semifor: Marc Mims <marc at questright.com>
 
+CONTRIBUTORS
+    mst: Matt S. Trout <mst at shadowcatsystems.co.uk>
+
+    mo: Moritz Onken <onken at netcubed.de>
+
+    norbi: Norbert Buchmuller <norbi at nix.hu>
+
 LICENSE
     You may distribute this code under the same terms as Perl itself.
 

Modified: DBIx-Class-InflateColumn-FS/1.000/trunk/lib/DBIx/Class/InflateColumn/FS.pm
===================================================================
--- DBIx-Class-InflateColumn-FS/1.000/trunk/lib/DBIx/Class/InflateColumn/FS.pm	2010-06-08 12:42:56 UTC (rev 9583)
+++ DBIx-Class-InflateColumn-FS/1.000/trunk/lib/DBIx/Class/InflateColumn/FS.pm	2010-06-22 16:49:42 UTC (rev 9584)
@@ -8,7 +8,7 @@
 use File::Copy ();
 use Path::Class ();
 
-our $VERSION = '0.01006';
+our $VERSION = '0.01007';
 
 =head1 NAME
 
@@ -277,6 +277,9 @@
         File::Copy::copy($fh1, $fh2);
 
         $self->{_inflated_column}{$column} = $file;
+
+        # ensure the column will be marked dirty
+        $self->{_column_data}{$column} = undef;
     }
     return $self->{_fs_column_filename}{$column};
 }
@@ -331,6 +334,14 @@
 
 semifor: Marc Mims <marc at questright.com>
 
+=head1 CONTRIBUTORS
+
+mst: Matt S. Trout <mst at shadowcatsystems.co.uk>
+
+mo: Moritz Onken <onken at netcubed.de>
+
+norbi: Norbert Buchmuller <norbi at nix.hu>
+
 =head1 LICENSE
 
 You may distribute this code under the same terms as Perl itself.

Modified: DBIx-Class-InflateColumn-FS/1.000/trunk/t/01-fs_columns.t
===================================================================
--- DBIx-Class-InflateColumn-FS/1.000/trunk/t/01-fs_columns.t	2010-06-08 12:42:56 UTC (rev 9583)
+++ DBIx-Class-InflateColumn-FS/1.000/trunk/t/01-fs_columns.t	2010-06-22 16:49:42 UTC (rev 9584)
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 use DBICx::TestDatabase;
-use Test::More tests => 24;
+use Test::More tests => 26;
 use Path::Class qw/file/;
 use File::Compare;
 use lib qw(t/lib);
@@ -61,6 +61,24 @@
 
 ok( compare($book->cover_image, $0) == 0, 'store from filehandle' );
 
+# missing fs_column
+{
+    my $book = $rs->create({ name => 'No cover image' });
+
+    ok ( !defined $book->cover_image, 'missing fs_column' );
+
+    open my $fh, '<', $0 or die "failed to open $0 for read: $!\n";
+
+    $book->cover_image($fh);
+    $book->update;
+    close $fh or die;
+
+    $book->discard_changes;   # reload from db
+
+    ok( defined $book->cover_image && compare($book->cover_image, $0) == 0,
+        'store from filehandle (missing fs column)' );
+}
+
 # setting fs_column to null should delete storage
 $book = $rs->create({ name => 'Here today, gone tomorrow',
         cover_image => $file });

Added: DBIx-Class-InflateColumn-FS/1.000/trunk/t/10-result_set.t
===================================================================
--- DBIx-Class-InflateColumn-FS/1.000/trunk/t/10-result_set.t	                        (rev 0)
+++ DBIx-Class-InflateColumn-FS/1.000/trunk/t/10-result_set.t	2010-06-22 16:49:42 UTC (rev 9584)
@@ -0,0 +1,101 @@
+#!perl
+use warnings;
+use strict;
+use DBICx::TestDatabase;
+use Test::More tests => 19;
+use Path::Class qw/file/;
+use File::Compare;
+use lib qw(t/lib);
+
+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 $file = file($0);
+
+my $book = $rs->create({
+    name => 'Alice in Wonderland',
+    cover_image => $file,
+});
+
+isa_ok( $book->cover_image, 'Path::Class::File' );
+isnt( $book->cover_image, $file, 'storage is a different file' );
+ok( compare($book->cover_image, $file) == 0, 'file contents equivalent');
+
+# setting a file to itself should be a no-op
+my $storage = Path::Class::File->new($book->cover_image);
+$book->update({ cover_image => $storage });
+
+is( $storage, $book->cover_image, 'setting storage to self' );
+
+# deleting the row should delete the associated file
+$book->delete;
+ok( ! -e $storage, 'file successfully deleted' );
+
+# multiple rows
+my ($book1, $book2) = map {
+    $rs->create({ name => $_, cover_image => $file })
+} qw/Book1 Book2/;
+
+isnt( $book1->cover_image, $book2->cover_image, 'rows have different storage' );
+
+$rs->delete;
+ok ( ! -e $book1->cover_image, "storage deleted for row 1" );
+ok ( ! -e $book2->cover_image, "storage deleted for row 2" );
+
+
+# null fs_column
+$book = $rs->create({ name => 'No cover image', cover_image => undef });
+
+ok ( !defined $book->cover_image, 'null fs_column' );
+
+
+# file handle
+open my $fh, '<', $0 or die "failed to open $0 for read: $!\n";
+
+$book->cover_image($fh);
+$book->update;
+close $fh or die;
+
+ok( compare($book->cover_image, $0) == 0, 'store from filehandle' );
+
+# setting fs_column to null should delete storage
+$book = $rs->create({ name => 'Here today, gone tomorrow',
+        cover_image => $file });
+$storage = $book->cover_image;
+ok( -e $storage, 'storage exists before nulling' );
+$book->update({ cover_image => undef });
+ok( ! -e $storage, 'does not exist after nulling' );
+
+$book->update({ cover_image => $file });
+$book->update({ id => 999 });
+$book->discard_changes;
+ok( -e $book->cover_image, 'storage renamed on PK change' );
+
+#--------------------------------- test copy ---------------------------------
+my $orig_column_data = { %{$book->{_column_data}} };
+my $copy = $book->copy;
+isnt( $copy->cover_image, $book->cover_image, 'copy has its own file backing' );
+ok( compare($copy->cover_image, $book->cover_image) == 0, 'copy contents correct' );
+
+# an update of book shouldn't change the source's _column_data
+is_deeply ( $book->{_column_data}, $orig_column_data, 'copy source unchanged' );
+
+# Regression test (failed on a prior implementation of copy)
+$book = $rs->find({ id => 1, });
+ok( eval{ $copy = $book->copy }, 'copy works with selected elements' );
+
+#----------------------------- infinite recursion ----------------------------
+$book = $rs->create({
+    name          => 'The Never Ending Story',
+    cover_image   => $file,
+    cover_image_2 => $file,
+});
+
+my $cover_image = $book->cover_image->stringify;
+my $cover_image_2 = $book->cover_image->stringify;
+$book->update({ cover_image => $file, cover_image_2 => $file });
+is( $book->cover_image, $cover_image, 'backing filename did not change' );
+isnt( $book->cover_image_2, $cover_image_2, 'backing filename did change for fs_new_on_update column' );

Modified: DBIx-Class-InflateColumn-FS/1.000/trunk/t/99-pod_spelling.t
===================================================================
--- DBIx-Class-InflateColumn-FS/1.000/trunk/t/99-pod_spelling.t	2010-06-08 12:42:56 UTC (rev 9583)
+++ DBIx-Class-InflateColumn-FS/1.000/trunk/t/99-pod_spelling.t	2010-06-22 16:49:42 UTC (rev 9584)
@@ -16,10 +16,14 @@
 
 __DATA__
 BLOBs
+Buchmuller
 FS
-fs
 IRC
 Marc
 Mims
+Onken
+fs
+mst
+norbi
 resultset
 semifor




More information about the Bast-commits mailing list