[Bast-commits] r6226 - in DBIx-Class/0.08/trunk/t: . delete

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Tue May 12 07:42:45 GMT 2009


Author: ribasushi
Date: 2009-05-12 07:42:45 +0000 (Tue, 12 May 2009)
New Revision: 6226

Added:
   DBIx-Class/0.08/trunk/t/delete/
   DBIx-Class/0.08/trunk/t/delete/m2m.t
   DBIx-Class/0.08/trunk/t/delete/related.t
Removed:
   DBIx-Class/0.08/trunk/t/53delete_related.t
   DBIx-Class/0.08/trunk/t/deleting_many_to_many.t
Log:
Shuffle delete tests, and sanify the delete related ones

Deleted: DBIx-Class/0.08/trunk/t/53delete_related.t
===================================================================
--- DBIx-Class/0.08/trunk/t/53delete_related.t	2009-05-12 06:43:58 UTC (rev 6225)
+++ DBIx-Class/0.08/trunk/t/53delete_related.t	2009-05-12 07:42:45 UTC (rev 6226)
@@ -1,30 +0,0 @@
-use Test::More;
-use strict;
-use warnings;
-use lib qw(t/lib);
-use DBICTest;
-
-plan tests => 7;
-
-my $schema = DBICTest->init_schema();
-my $total_cds = $schema->resultset('CD')->count;
-cmp_ok($total_cds, '>', 0, 'need cd records');
-
-# test that delete_related w/o conditions deletes all related records only
-my $artist = $schema->resultset("Artist")->find(3);
-my $artist_cds = $artist->cds->count;
-cmp_ok($artist_cds, '<', $total_cds, 'need more cds than just related cds');
-
-ok($artist->delete_related('cds'));
-cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist_cds), 'wrong number of cds were deleted');
-
-$total_cds -= $artist_cds;
-
-# test that delete_related w/conditions deletes just the matched related records only
-my $artist2 = $schema->resultset("Artist")->find(2);
-my $artist2_cds = $artist2->search_related('cds')->count;
-cmp_ok($artist2_cds, '<', $total_cds, 'need more cds than related cds');
-
-ok($artist2->delete_related('cds', {title => {like => '%'}}));
-cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist2_cds), 'wrong number of cds were deleted');
-

Copied: DBIx-Class/0.08/trunk/t/delete/m2m.t (from rev 4161, DBIx-Class/0.08/trunk/t/deleting_many_to_many.t)
===================================================================
--- DBIx-Class/0.08/trunk/t/delete/m2m.t	                        (rev 0)
+++ DBIx-Class/0.08/trunk/t/delete/m2m.t	2009-05-12 07:42:45 UTC (rev 6226)
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;  
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+plan tests => 5;
+
+my $cd = $schema->resultset("CD")->find(2);
+ok $cd->liner_notes;
+ok keys %{$cd->{_relationship_data}}, "_relationship_data populated";
+
+$cd->discard_changes;
+ok $cd->liner_notes, 'relationships still valid after discarding changes';
+
+ok $cd->liner_notes->delete;
+$cd->discard_changes;
+ok !$cd->liner_notes, 'discard_changes resets relationship';
\ No newline at end of file

Copied: DBIx-Class/0.08/trunk/t/delete/related.t (from rev 4956, DBIx-Class/0.08/trunk/t/53delete_related.t)
===================================================================
--- DBIx-Class/0.08/trunk/t/delete/related.t	                        (rev 0)
+++ DBIx-Class/0.08/trunk/t/delete/related.t	2009-05-12 07:42:45 UTC (rev 6226)
@@ -0,0 +1,40 @@
+use Test::More;
+use strict;
+use warnings;
+use lib qw(t/lib);
+use DBICTest;
+
+plan tests => 3;
+
+my $schema = DBICTest->init_schema();
+
+my $ars = $schema->resultset('Artist');
+my $cdrs = $schema->resultset('CD');
+
+# create some custom entries
+$ars->create ({ artistid => 9, name => 'dead man walking' });
+$cdrs->populate ([
+  [qw/cdid artist title   year/],
+  [qw/70   2      delete0 2005/],
+  [qw/71   3      delete1 2005/],
+  [qw/72   3      delete2 2005/],
+  [qw/73   3      delete3 2006/],
+  [qw/74   3      delete4 2007/],
+  [qw/75   9      delete5 2008/],
+]);
+
+my $total_cds = $cdrs->count;
+
+# test that delete_related w/o conditions deletes all related records only
+$ars->find (9)->delete_related ('cds');
+is ($cdrs->count, $total_cds -= 1, 'related delete ok');
+
+my $a3_cds = $ars->find(3)->cds;
+
+# test that related deletion w/conditions deletes just the matched related records only
+$a3_cds->search ({ year => 2005 })->delete;
+is ($cdrs->count, $total_cds -= 2, 'related + condition delete ok');
+
+# test that related deletion with limit condition works
+$a3_cds->search ({}, { rows => 1})->delete;
+is ($cdrs->count, $total_cds -= 1, 'related + limit delete ok');

Deleted: DBIx-Class/0.08/trunk/t/deleting_many_to_many.t
===================================================================
--- DBIx-Class/0.08/trunk/t/deleting_many_to_many.t	2009-05-12 06:43:58 UTC (rev 6225)
+++ DBIx-Class/0.08/trunk/t/deleting_many_to_many.t	2009-05-12 07:42:45 UTC (rev 6226)
@@ -1,23 +0,0 @@
-#!/usr/bin/perl -w
-
-use strict;
-use warnings;  
-
-use Test::More;
-use lib qw(t/lib);
-use DBICTest;
-
-my $schema = DBICTest->init_schema();
-
-plan tests => 5;
-
-my $cd = $schema->resultset("CD")->find(2);
-ok $cd->liner_notes;
-ok keys %{$cd->{_relationship_data}}, "_relationship_data populated";
-
-$cd->discard_changes;
-ok $cd->liner_notes, 'relationships still valid after discarding changes';
-
-ok $cd->liner_notes->delete;
-$cd->discard_changes;
-ok !$cd->liner_notes, 'discard_changes resets relationship';
\ No newline at end of file




More information about the Bast-commits mailing list