Added t/09update.t from Alexander Hartmeier and changes to pass it
Matt S Trout [Tue, 2 Aug 2005 15:07:56 +0000 (15:07 +0000)]
lib/DBIx/Class/Table.pm
t/09update.t [new file with mode: 0644]

index d8b6658..4163480 100644 (file)
@@ -127,8 +127,9 @@ sub get_column {
 sub set_column {
   my $self = shift;
   my ($column) = @_;
+  my $old = $self->get_column($column);
   my $ret = $self->store_column(@_);
-  $self->{_dirty_columns}{$column} = 1;
+  $self->{_dirty_columns}{$column} = 1 unless defined $old && $old eq $ret;
   return $ret;
 }
 
@@ -251,6 +252,10 @@ sub retrieve_all {
   return $class->retrieve_from_sql( '1' );
 }
 
+sub is_changed {
+  return keys %{shift->{_dirty_columns} || {}};
+}
+
 1;
 
 =back
diff --git a/t/09update.t b/t/09update.t
new file mode 100644 (file)
index 0000000..ec90358
--- /dev/null
@@ -0,0 +1,26 @@
+use strict;
+use Test::More;
+
+BEGIN {
+        eval "use DBD::SQLite";
+        plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 4);
+}                                                                               
+
+use lib qw(t/lib);
+
+use_ok('DBICTest');
+
+my $art = DBICTest::Artist->retrieve(1);
+
+isa_ok $art => 'DBICTest::Artist';
+
+my $name = 'Caterwauler McCrae';
+
+ok($art->name($name) eq $name, 'update');
+
+{ 
+  my @changed_keys = $art->is_changed;
+  is( scalar (@changed_keys), 0, 'field changed but same value' );
+}                                                                               
+
+$art->discard_changes;