From: Matt S Trout Date: Tue, 2 Aug 2005 15:07:56 +0000 (+0000) Subject: Added t/09update.t from Alexander Hartmeier and changes to pass it X-Git-Tag: v0.03001~93 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cc0f266f9a5303f1ca7856fbbba5d0154f630409;p=dbsrgits%2FDBIx-Class.git Added t/09update.t from Alexander Hartmeier and changes to pass it --- diff --git a/lib/DBIx/Class/Table.pm b/lib/DBIx/Class/Table.pm index d8b6658..4163480 100644 --- a/lib/DBIx/Class/Table.pm +++ b/lib/DBIx/Class/Table.pm @@ -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 index 0000000..ec90358 --- /dev/null +++ b/t/09update.t @@ -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;