X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F80unique.t;h=0e4108bf0cd7952c216858654acd413a9597a720;hb=94fa8410d3be08104badc97d694d16fe287b602d;hp=6108f289983d6c46a5704d95f522eefbbc7128c9;hpb=d180c0f33c2fbbe3a20f994b1c61703c67128e6e;p=dbsrgits%2FDBIx-Class.git diff --git a/t/80unique.t b/t/80unique.t index 6108f28..0e4108b 100644 --- a/t/80unique.t +++ b/t/80unique.t @@ -1,14 +1,14 @@ use strict; -use warnings; +use warnings; use Test::More; use lib qw(t/lib); use DBICTest; +use DBIC::SqlMakerTest; +use DBIC::DebugObj; my $schema = DBICTest->init_schema(); -plan tests => 45; - # Check the defined unique constraints is_deeply( [ sort $schema->source('CD')->unique_constraint_names ], @@ -183,3 +183,53 @@ is($row->baz, 3, 'baz is correct'); ok($cd->in_storage, 'find correctly grepped the key across a relationship'); is($cd->cdid, 1, 'cdid is correct'); } + +# Test update_or_new +{ + my $cd1 = $schema->resultset('CD')->update_or_new( + { + artist => $artistid, + title => "SuperHits $$", + year => 2007, + }, + { key => 'cd_artist_title' } + ); + + is($cd1->in_storage, 0, 'CD is not in storage yet after update_or_new'); + $cd1->insert; + ok($cd1->in_storage, 'CD got added to strage after update_or_new && insert'); + + my $cd2 = $schema->resultset('CD')->update_or_new( + { + artist => $artistid, + title => "SuperHits $$", + year => 2008, + }, + { key => 'cd_artist_title' } + ); + ok($cd2->in_storage, 'Updating year using update_or_new was successful'); + is($cd2->id, $cd1->id, 'Got the same CD using update_or_new'); +} + +# make sure the ident condition is assembled sanely +{ + my $artist = $schema->resultset('Artist')->next; + + my ($sql, @bind); + $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), + $schema->storage->debug(1); + + $artist->discard_changes; + + is_same_sql_bind ( + $sql, + \@bind, + 'SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE me.artistid = ?', + [qw/'1'/], + ); + + $schema->storage->debug(0); + $schema->storage->debugobj(undef); +} + +done_testing;