X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-DBIx-Class-ResultSet-RecursiveUpdate;a=blobdiff_plain;f=t%2Flib%2FRunTests.pm;h=8e5afa8e3bc0e83b01aa125ea8497345140cceff;hp=93255b653c6e9e7fcfdffbde61377a7e8b0a01cc;hb=df9cba8acd38f0929da6d62ec6980cbc3415421a;hpb=454db15e55f697bb4c64b52d1d9403a30361bede diff --git a/t/lib/RunTests.pm b/t/lib/RunTests.pm index 93255b6..8e5afa8 100644 --- a/t/lib/RunTests.pm +++ b/t/lib/RunTests.pm @@ -9,7 +9,7 @@ use DBIx::Class::ResultSet::RecursiveUpdate; sub run_tests{ my $schema = shift; - plan tests => 30; + plan tests => 36; my $dvd_rs = $schema->resultset( 'Dvd' ); my $user_rs = $schema->resultset( 'User' ); @@ -165,6 +165,40 @@ sub run_tests{ $dvd = $dvd_rs->find( 1 ); is( $dvd->get_column( 'owner' ), $user->id, 'foreign key set' ); + $dvd_rs->update( { current_borrower => $user->id } ); + ok( $user->borrowed_dvds->count > 1, 'Precond' ); + $updates = { + id => $user->id, + borrowed_dvds =>[ + { + id => $dvd->id + }, + ] + }; + $user = DBIx::Class::ResultSet::RecursiveUpdate::Functions::recursive_update( + resultset => $user_rs, + updates => $updates, + if_not_submitted => 'set_to_null', + ); + is( $user->borrowed_dvds->count, 1, 'set_to_null' ); + + $dvd_rs->update( { current_borrower => $user->id } ); + $updates = { + id => $user->id, + borrowed_dvds =>[ + { + id => $dvd->id + }, + ] + }; + $user = DBIx::Class::ResultSet::RecursiveUpdate::Functions::recursive_update( + resultset => $user_rs, + updates => $updates, + if_not_submitted => 'delete', + ); + is( $user->borrowed_dvds->count, 1, 'if_not_submitted delete' ); + + # $updates = { # name => 'Test name 1', # };