[Bast-commits] r7280 - in DBIx-Class/0.08/trunk/t: . create lib
lib/DBICTest/Schema prefetch
mo at dev.catalyst.perl.org
mo at dev.catalyst.perl.org
Sun Aug 9 17:10:57 GMT 2009
Author: mo
Date: 2009-08-09 17:10:56 +0000 (Sun, 09 Aug 2009)
New Revision: 7280
Added:
DBIx-Class/0.08/trunk/t/create/
DBIx-Class/0.08/trunk/t/create/set_column.t
Modified:
DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Track.pm
DBIx-Class/0.08/trunk/t/lib/sqlite.sql
DBIx-Class/0.08/trunk/t/prefetch/double_prefetch.t
DBIx-Class/0.08/trunk/t/prefetch/grouped.t
Log:
added TODO test: call accessors when create()ing a row
Added: DBIx-Class/0.08/trunk/t/create/set_column.t
===================================================================
--- DBIx-Class/0.08/trunk/t/create/set_column.t (rev 0)
+++ DBIx-Class/0.08/trunk/t/create/set_column.t 2009-08-09 17:10:56 UTC (rev 7280)
@@ -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;
Modified: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Track.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Track.pm 2009-08-09 14:17:03 UTC (rev 7279)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Track.pm 2009-08-09 17:10:56 UTC (rev 7280)
@@ -34,6 +34,11 @@
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__->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;
Modified: DBIx-Class/0.08/trunk/t/lib/sqlite.sql
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/sqlite.sql 2009-08-09 14:17:03 UTC (rev 7279)
+++ DBIx-Class/0.08/trunk/t/lib/sqlite.sql 2009-08-09 17:10:56 UTC (rev 7280)
@@ -285,7 +285,8 @@
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);
Modified: DBIx-Class/0.08/trunk/t/prefetch/double_prefetch.t
===================================================================
--- DBIx-Class/0.08/trunk/t/prefetch/double_prefetch.t 2009-08-09 14:17:03 UTC (rev 7279)
+++ DBIx-Class/0.08/trunk/t/prefetch/double_prefetch.t 2009-08-09 17:10:56 UTC (rev 7280)
@@ -23,8 +23,8 @@
'(
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
Modified: DBIx-Class/0.08/trunk/t/prefetch/grouped.t
===================================================================
--- DBIx-Class/0.08/trunk/t/prefetch/grouped.t 2009-08-09 14:17:03 UTC (rev 7279)
+++ DBIx-Class/0.08/trunk/t/prefetch/grouped.t 2009-08-09 17:10:56 UTC (rev 7280)
@@ -163,7 +163,7 @@
$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
More information about the Bast-commits
mailing list