From: Andy Grundman Date: Wed, 3 Aug 2005 14:17:45 +0000 (+0000) Subject: Added tests for insert_or_update, moved Auto test to own file X-Git-Tag: v0.03001~82 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b6e40530b8ef2ef333b7466a6cd131c460872d03;hp=570efc13c4b1856f1a5f63b09680e25dcb6195cb;p=dbsrgits%2FDBIx-Class.git Added tests for insert_or_update, moved Auto test to own file --- diff --git a/t/01core.t b/t/01core.t index 93c211d..20090c0 100644 --- a/t/01core.t +++ b/t/01core.t @@ -1,6 +1,6 @@ use Test::More; -plan tests => 21; +plan tests => 22; use lib qw(t/lib); @@ -76,14 +76,17 @@ is($new_again->name, 'Man With A Spoon', 'Retrieved correctly'); is(DBICTest::Artist->count, 4, 'count ok'); -use DBIx::Class::PK::Auto; -use DBIx::Class::PK::Auto::SQLite; - -unshift(@DBICTest::Artist::ISA, qw/DBIx::Class::PK::Auto - DBIx::Class::PK::Auto::SQLite/); - -# add an artist without primary key to test Auto -my $artist = DBICTest::Artist->create( { name => 'Auto' } ); -$artist->name( 'Auto Change' ); -ok($artist->update, 'update on object created without PK ok'); - +# insert_or_update +$new = DBICTest::Track->new( { + trackid => 100, + cd => 1, + position => 1, + title => 'Insert or Update', +} ); +$new->insert_or_update; +ok($new->in_database, 'insert_or_update insert ok'); + +# test in update mode +$new->position(5); +$new->insert_or_update; +is( DBICTest::Track->retrieve(100)->position, 5, 'insert_or_update update ok'); diff --git a/t/06relationship.t b/t/06relationship.t index b395599..ea74a3a 100644 --- a/t/06relationship.t +++ b/t/06relationship.t @@ -59,7 +59,7 @@ $cd = $artist->find_or_create_related( 'cds', { year => 2006, } ); is( $cd->title, 'Greatest Hits', 'find_or_create_related new record ok' ); -my @cds = $artist->search_related('cds'); +@cds = $artist->search_related('cds'); is( ($artist->search_related('cds'))[4]->title, 'Greatest Hits', 'find_or_create_related new record search ok' ); SKIP: { diff --git a/t/10auto.t b/t/10auto.t new file mode 100644 index 0000000..4cf63c3 --- /dev/null +++ b/t/10auto.t @@ -0,0 +1,18 @@ +use Test::More; + +use DBIx::Class::PK::Auto; +use DBIx::Class::PK::Auto::SQLite; + +plan tests => 2; + +use lib qw(t/lib); + +use_ok('DBICTest'); + +unshift(@DBICTest::Artist::ISA, qw/DBIx::Class::PK::Auto + DBIx::Class::PK::Auto::SQLite/); + +# add an artist without primary key to test Auto +my $artist = DBICTest::Artist->create( { name => 'Auto' } ); +$artist->name( 'Auto Change' ); +ok($artist->update, 'update on object created without PK ok');