From: Michael G Schwern Date: Wed, 13 Feb 2008 07:06:42 +0000 (-0800) Subject: Test that DateTime objects can safely be updated twice (which is what triggers X-Git-Tag: v0.08240~541^2~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4c9f72c1b6c90bdba16fbaa481c5eb77f73a43e6;p=dbsrgits%2FDBIx-Class.git Test that DateTime objects can safely be updated twice (which is what triggers the equality check). Remove the stringification to shield broken equality since DateTime seems to work. This also shuts up a warning in GetSet when you set to an undef value. Test that. Change from bitwise xor to regular xor since bitwise is overkill and nobody knows what ^ is. --- diff --git a/lib/DBIx/Class/CDBICompat/GetSet.pm b/lib/DBIx/Class/CDBICompat/GetSet.pm index a11baeb..80e941f 100644 --- a/lib/DBIx/Class/CDBICompat/GetSet.pm +++ b/lib/DBIx/Class/CDBICompat/GetSet.pm @@ -17,11 +17,6 @@ sub get { sub set { my($self, %data) = @_; - - # set_columns() is going to do a string comparison before setting. - # This breaks on DateTime objects (whose comparison is arguably broken) - # so we stringify anything first. - $data{$_} = "$data{$_}" for keys %data; return shift->set_columns(\%data); } diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 6e348d3..1bc569f 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -460,7 +460,7 @@ sub set_column { my $old = $self->get_column($column); my $ret = $self->store_column(@_); $self->{_dirty_columns}{$column} = 1 - if (defined $old ^ defined $ret) || (defined $old && $old ne $ret); + if (defined $old xor defined $ret) || (defined $old && $old ne $ret); # XXX clear out the relation cache for this column delete $self->{related_resultsets}{$column}; diff --git a/t/cdbi-t/set_to_undef.t b/t/cdbi-t/set_to_undef.t new file mode 100644 index 0000000..bad9919 --- /dev/null +++ b/t/cdbi-t/set_to_undef.t @@ -0,0 +1,25 @@ +#!/usr/bin/perl -w + +use strict; +use Test::More; +use Test::NoWarnings; + +BEGIN { + eval "use DBIx::Class::CDBICompat;"; + plan skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@" + if $@; + plan skip_all => "DateTime required" unless eval { require DateTime }; + plan tests => 1; +} + +{ + package Thing; + + use base 'DBIx::Class::Test::SQLite'; + + Thing->columns(All => qw[thing_id this that date]); +} + +my $thing = Thing->construct({ thing_id => 23, this => 42 }); +$thing->set( this => undef ); +$thing->discard_changes; diff --git a/t/cdbi-t/set_vs_DateTime.t b/t/cdbi-t/set_vs_DateTime.t index 84842bf..fb76561 100644 --- a/t/cdbi-t/set_vs_DateTime.t +++ b/t/cdbi-t/set_vs_DateTime.t @@ -2,6 +2,7 @@ use strict; use Test::More; +use Test::Exception; BEGIN { eval "use DBIx::Class::CDBICompat;"; @@ -20,9 +21,12 @@ BEGIN { } my $thing = Thing->construct({ thing_id => 23, date => "01-02-1994" }); -eval { - $thing->set( date => DateTime->now ); +my $date = DateTime->now; +lives_ok { + $thing->set( date => $date ); + $thing->set( date => $date ); }; -is $@, ''; + + $thing->discard_changes;