[Bast-commits] r7953 - in DBIx-Class/0.08/branches/create_scalarref_rt51559: lib/DBIx/Class t/inflate

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Wed Nov 25 23:19:22 GMT 2009


Author: ribasushi
Date: 2009-11-25 23:19:21 +0000 (Wed, 25 Nov 2009)
New Revision: 7953

Modified:
   DBIx-Class/0.08/branches/create_scalarref_rt51559/lib/DBIx/Class/InflateColumn.pm
   DBIx-Class/0.08/branches/create_scalarref_rt51559/t/inflate/core.t
Log:
Test and fix scalarref in an inflatable slot corner-case

Modified: DBIx-Class/0.08/branches/create_scalarref_rt51559/lib/DBIx/Class/InflateColumn.pm
===================================================================
--- DBIx-Class/0.08/branches/create_scalarref_rt51559/lib/DBIx/Class/InflateColumn.pm	2009-11-25 20:24:10 UTC (rev 7952)
+++ DBIx-Class/0.08/branches/create_scalarref_rt51559/lib/DBIx/Class/InflateColumn.pm	2009-11-25 23:19:21 UTC (rev 7953)
@@ -124,8 +124,11 @@
     unless exists $self->column_info($col)->{_inflate_info};
   return $self->{_inflated_column}{$col}
     if exists $self->{_inflated_column}{$col};
-  return $self->{_inflated_column}{$col} =
-           $self->_inflated_column($col, $self->get_column($col));
+
+  my $val = $self->get_column($col);
+  return $val if ref $val eq 'SCALAR';  #that would be a not-yet-reloaded sclarref update
+
+  return $self->{_inflated_column}{$col} = $self->_inflated_column($col, $val);
 }
 
 =head2 set_inflated_column

Modified: DBIx-Class/0.08/branches/create_scalarref_rt51559/t/inflate/core.t
===================================================================
--- DBIx-Class/0.08/branches/create_scalarref_rt51559/t/inflate/core.t	2009-11-25 20:24:10 UTC (rev 7952)
+++ DBIx-Class/0.08/branches/create_scalarref_rt51559/t/inflate/core.t	2009-11-25 23:19:21 UTC (rev 7953)
@@ -16,8 +16,10 @@
       deflate => sub { shift->year } }
 );
 
+my $rs = $schema->resultset('CD');
+
 # inflation test
-my $cd = $schema->resultset("CD")->find(3);
+my $cd = $rs->find(3);
 
 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
 
@@ -45,7 +47,7 @@
 $cd->year( $now );
 $cd->update;
 
-$cd = $schema->resultset("CD")->find(3);
+$cd = $rs->find(3);
 is( $cd->year->year, $now->year, 'deflate ok' );
 
 # set_inflated_column test
@@ -53,10 +55,10 @@
 ok(!$@, 'set_inflated_column with DateTime object');
 $cd->update;
 
-$cd = $schema->resultset("CD")->find(3);
+$cd = $rs->find(3);
 is( $cd->year->year, $now->year, 'deflate ok' );
 
-$cd = $schema->resultset("CD")->find(3);
+$cd = $rs->find(3);
 my $before_year = $cd->year->year;
 eval { $cd->set_inflated_column('year', \'year + 1') };
 ok(!$@, 'set_inflated_column to "year + 1"');
@@ -71,11 +73,11 @@
   }, 'store_inflated_column to "year + 1"');
 }
 
-$cd = $schema->resultset("CD")->find(3);
+$cd = $rs->find(3);
 is( $cd->year->year, $before_year+1, 'deflate ok' );
 
 # store_inflated_column test
-$cd = $schema->resultset("CD")->find(3);
+$cd = $rs->find(3);
 eval { $cd->store_inflated_column('year', $now) };
 ok(!$@, 'store_inflated_column with DateTime object');
 $cd->update;
@@ -83,21 +85,21 @@
 is( $cd->year->year, $now->year, 'deflate ok' );
 
 # update tests
-$cd = $schema->resultset("CD")->find(3);
+$cd = $rs->find(3);
 eval { $cd->update({'year' => $now}) };
 ok(!$@, 'update using DateTime object ok');
 is($cd->year->year, $now->year, 'deflate ok');
 
-$cd = $schema->resultset("CD")->find(3);
+$cd = $rs->find(3);
 $before_year = $cd->year->year;
 eval { $cd->update({'year' => \'year + 1'}) };
 ok(!$@, 'update using scalarref ok');
 
-$cd = $schema->resultset("CD")->find(3);
+$cd = $rs->find(3);
 is($cd->year->year, $before_year + 1, 'deflate ok');
 
 # discard_changes test
-$cd = $schema->resultset("CD")->find(3);
+$cd = $rs->find(3);
 # inflate the year
 $before_year = $cd->year->year;
 $cd->update({ year => \'year + 1'});
@@ -107,6 +109,45 @@
 
 my $copy = $cd->copy({ year => $now, title => "zemoose" });
 
-isnt( $copy->year->year, $before_year, "copy" );
+is( $copy->year->year, $now->year, "copy" );
 
+
+
+my $artist = $cd->artist;
+my $sval = \ '2012';
+
+$cd = $rs->create ({
+        artist => $artist,
+        year => $sval,
+        title => 'create with scalarref',
+});
+
+is ($cd->year, $sval, 'scalar value retained');
+my $cd2 = $cd->copy ({ title => 'copy with scalar in coldata' });
+is ($cd2->year, $sval, 'copied scalar value retained');
+
+$cd->discard_changes;
+is ($cd->year->year, 2012, 'infation upon reload');
+
+$cd2->discard_changes;
+is ($cd2->year->year, 2012, 'infation upon reload of copy');
+
+
+my $precount = $rs->count;
+$cd = $rs->update_or_create ({artist => $artist, title => 'nonexisting update/create test row', year => $sval });
+is ($rs->count, $precount + 1, 'Row created');
+
+is ($cd->year, $sval, 'scalar value retained on creating update_or_create');
+$cd->discard_changes;
+is ($cd->year->year, 2012, 'infation upon reload');
+
+my $sval2 = \ '2013';
+
+$cd = $rs->update_or_create ({artist => $artist, title => 'nonexisting update/create test row', year => $sval2 });
+is ($rs->count, $precount + 1, 'No more rows created');
+
+is ($cd->year, $sval2, 'scalar value retained on updating update_or_create');
+$cd->discard_changes;
+is ($cd->year->year, 2013, 'infation upon reload');
+
 done_testing;




More information about the Bast-commits mailing list