From: Moritz Onken Date: Sun, 9 Aug 2009 17:10:56 +0000 (+0000) Subject: added TODO test: call accessors when create()ing a row X-Git-Tag: v0.08109~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=27d619d8c3100065f87bdbcc7c1496cb2e5495c9;p=dbsrgits%2FDBIx-Class.git added TODO test: call accessors when create()ing a row --- diff --git a/t/create/set_column.t b/t/create/set_column.t new file mode 100644 index 0000000..2cc462b --- /dev/null +++ b/t/create/set_column.t @@ -0,0 +1,47 @@ +use warnings; +use strict; + +use Test::More; + +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +TODO: { + local $TODO = 'call accessors when calling create() or update()'; + + my $row = + $schema->resultset('Track')->new_result( { title => 'foo', cd => 1 } ); + $row->increment(1); + $row->insert; + is( $row->increment, 2 ); + + $row = + $schema->resultset('Track') + ->create( { title => 'bar', cd => 1, increment => 1 } ); + is( $row->increment, 2 ); + + # $row isa DBICTest::Schema::Track + $row->get_from_storage; + is( $row->increment, 2 ); + + $row->update( { increment => 3 } ); + $row->get_from_storage; + is( $row->increment, 4 ); + + $row->increment(3); + $row->get_from_storage; + is( $row->increment, 4 ); + + eval { + $row = + $schema->resultset('Track') + ->create( { title => 'bar', cd => 2, set_increment => 1 } ); + }; + ok( !$@, 'lives ok' ); + is( $row->increment, 1 ); + +} + +done_testing; diff --git a/t/lib/DBICTest/Schema/Track.pm b/t/lib/DBICTest/Schema/Track.pm index a6de595..948597d 100644 --- a/t/lib/DBICTest/Schema/Track.pm +++ b/t/lib/DBICTest/Schema/Track.pm @@ -34,6 +34,11 @@ __PACKAGE__->add_columns( data_type => 'smalldatetime', is_nullable => 1 }, + increment => { + data_type => 'integer', + is_nullable => 1, + accessor => '_increment', + } ); __PACKAGE__->set_primary_key('trackid'); @@ -50,4 +55,20 @@ __PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd'); __PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' ); __PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' ); +sub increment { + my $self = shift; + if(@_) { + return $self->_increment($_[0] + 1); + } + return $self->_increment(); +} + +sub set_increment { + my $self = shift; + if(@_) { + return $self->_increment($_[0]); + } + return $self->_increment(); +} + 1; diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index 20b8e5a..ce8be83 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -285,7 +285,8 @@ CREATE TABLE track ( title varchar(100) NOT NULL, last_updated_on datetime, last_updated_at datetime, - small_dt smalldatetime + small_dt smalldatetime, + increment integer ); CREATE INDEX track_idx_cd ON track (cd); diff --git a/t/prefetch/double_prefetch.t b/t/prefetch/double_prefetch.t index 6142098..f518f73 100644 --- a/t/prefetch/double_prefetch.t +++ b/t/prefetch/double_prefetch.t @@ -23,8 +23,8 @@ is_same_sql( '( SELECT cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track, - single_track.trackid, single_track.cd, single_track.position, single_track.title, single_track.last_updated_on, single_track.last_updated_at, single_track.small_dt, - single_track_2.trackid, single_track_2.cd, single_track_2.position, single_track_2.title, single_track_2.last_updated_on, single_track_2.last_updated_at, single_track_2.small_dt, + single_track.trackid, single_track.cd, single_track.position, single_track.title, single_track.last_updated_on, single_track.last_updated_at, single_track.small_dt, single_track.increment, + single_track_2.trackid, single_track_2.cd, single_track_2.position, single_track_2.title, single_track_2.last_updated_on, single_track_2.last_updated_at, single_track_2.small_dt, single_track_2.increment, cd.cdid, cd.artist, cd.title, cd.year, cd.genreid, cd.single_track FROM artist me LEFT JOIN cd cds ON cds.artist = me.artistid diff --git a/t/prefetch/grouped.t b/t/prefetch/grouped.t index 92f383c..bd50a9d 100644 --- a/t/prefetch/grouped.t +++ b/t/prefetch/grouped.t @@ -163,7 +163,7 @@ for ($cd_rs->all) { $most_tracks_rs->as_query, '( SELECT me.cdid, me.track_count, - tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at, tracks.small_dt, + tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at, tracks.small_dt, tracks.increment, liner_notes.liner_id, liner_notes.notes FROM ( SELECT me.cdid, COUNT( tracks.trackid ) AS track_count