Add a proof of concept test for copy() with assymetric IC::DT
[dbsrgits/DBIx-Class.git] / t / icdt / engine_specific / sybase.t
index 72a8bdb..993fa9b 100644 (file)
@@ -7,6 +7,7 @@ use warnings;
 use Test::More;
 use Test::Exception;
 use DBIx::Class::_Util 'scope_guard';
+use Sub::Name;
 
 use DBICTest;
 
@@ -94,7 +95,7 @@ SQL
           %$create_extra,
         }));
     ok( $row = $schema->resultset($source)
-      ->search({ $pk => $row->$pk }, { select => [$col] })
+      ->search({ $pk => $row->$pk }, { select => [$pk, $col] })
       ->first
     );
     is( $row->$col, $dt, "$type roundtrip" );
@@ -102,6 +103,46 @@ SQL
     cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
       'DateTime fractional portion roundtrip' )
       if exists $sample_dt->{nanosecond};
+
+    # Testing an ugly half-solution
+    #
+    # copy() uses get_columns()
+    #
+    # The values should survive a roundtrip also, but they don't
+    # because the Sybase ICDT setup is asymmetric
+    # One *has* to force an inflation/deflation cycle to make the
+    # values usable to the database
+    #
+    # This can be done by marking the columns as dirty, and there
+    # are tests for this already in t/inflate/serialize.t
+    #
+    # But even this isn't enough - one has to reload the RDBMS-formatted
+    # values once done, otherwise the copy is just as useless... sigh
+    #
+    # Adding the test here to validate the technique works
+    # UGH!
+    {
+      no warnings 'once';
+      local *DBICTest::BaseResult::copy = subname 'DBICTest::BaseResult::copy' => sub {
+        my $self = shift;
+
+        $self->make_column_dirty($_) for keys %{{ $self->get_inflated_columns }};
+
+        my $cp = $self->next::method(@_);
+
+        $cp->discard_changes({ columns => [ keys %{{ $cp->get_columns }} ] });
+      };
+      Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
+
+      my $cp = $row->copy;
+      ok( $cp->in_storage );
+      is( $cp->$col, $dt, "$type copy logical roundtrip" );
+
+      $cp->discard_changes({ select => [ $pk, $col ] });
+      is( $cp->$col, $dt, "$type copy server roundtrip" );
+    }
+
+    Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
   }
 
   # test a computed datetime column