]> Dogcows Code - chaz/p5-DBIx-Class-ResultSet-RecursiveUpdate/blobdiff - t/lib/RunTests.pm
doc improvements
[chaz/p5-DBIx-Class-ResultSet-RecursiveUpdate] / t / lib / RunTests.pm
index b5eef51ffe3e3627483ef95f499167e5564dfa90..d0fce5b74b594cac099cd64bd7eca35c3517fdad 100644 (file)
@@ -9,7 +9,7 @@ use DBIx::Class::ResultSet::RecursiveUpdate;
 sub run_tests {
     my $schema = shift;
 
-    plan tests => 42;
+    plan tests => 47;
 
     my $dvd_rs  = $schema->resultset('Dvd');
     my $user_rs = $schema->resultset('User');
@@ -20,6 +20,15 @@ sub run_tests {
     my $initial_dvd_count  = $dvd_rs->count;
     my $updates;
 
+    $dvd_rs->search( { dvd_id => 1 } )->recursive_update( { 
+            owner =>  { username => 'aaa'  } 
+        },
+        [ 'dvd_id' ]
+    );
+
+    my $u = $user_rs->find( $dvd_rs->find( 1 )->owner->id );
+    is( $u->username, 'aaa', 'fixed_fields' );
+
     # try to create with a not existing rel
     $updates = {
         name        => 'Test name for nonexisting rel',
@@ -95,13 +104,17 @@ sub run_tests {
             ->find( { key1 => $onekey->id, key2 => 1 } ),
         'Twokeys_belongsto created'
     );
+    TODO: {
+        local $TODO = 'value of fk from a multi relationship';
+        is( $dvd->twokeysfk, $onekey->id, 'twokeysfk in Dvd' );
+    };
     is( $dvd->name, 'Test name', 'Dvd name set' );
 
     # changing existing records
     my $num_of_users = $user_rs->count;
     $updates = {
-        id => $dvd->dvd_id,    # id instead of dvd_id
-        ####aaaa => undef,
+        id               => $dvd->dvd_id,         # id instead of dvd_id
+                                                  #aaaa => undef,
         name             => undef,
         tags             => [],
         'owner'          => $another_owner->id,
@@ -194,14 +207,6 @@ sub run_tests {
     $dvd = $dvd_rs->find(1);
     is( $dvd->get_column('owner'), $user->id, 'foreign key set' );
 
-    # # delete has_many where foreign cols aren't nullable
-    # $updates = {
-    # id => $user->id,
-    # owned_dvds => undef,
-    # };
-    # $user = $user_rs->recursive_update( $updates );
-    # ok ( !$dvd_rs->find( 1 ), 'owned dvd deleted');
-
     $dvd_rs->update( { current_borrower => $user->id } );
     ok( $user->borrowed_dvds->count > 1, 'Precond' );
     $updates = {
@@ -257,7 +262,17 @@ sub run_tests {
     };
     ok( my $new_user = $user_rs->recursive_update($new_person) );
 
-    #print STDERR Dumper $new_user;
+    # delete has_many where foreign cols aren't nullable
+    my $rs_user_dvd = $user->owned_dvds;
+    my @user_dvd_ids = map { $_->id } $rs_user_dvd->all;
+    is( $rs_user_dvd->count, 1, 'user owns 1 dvd');
+    $updates = {
+        id         => $user->id,
+        owned_dvds => undef,
+    };
+    $user = $user_rs->recursive_update($updates);
+    is( $user->owned_dvds->count, 0, 'user owns no dvds');
+    is( $dvd_rs->search({ dvd_id => {-in => \@user_dvd_ids }})->count, 0, 'owned dvds deleted' );
 
 #    $updates = {
 #            name => 'Test name 1',
This page took 0.022185 seconds and 4 git commands to generate.