added tests for RT#63709 wip/where_relattr_tests
Alexander Hartmaier [Thu, 16 Dec 2010 14:52:53 +0000 (15:52 +0100)]
t/lib/DBICTest/Schema/Artist.pm
t/prefetch/relationship_where_attr.t [new file with mode: 0644]

index 8087292..c993d72 100644 (file)
@@ -134,6 +134,10 @@ __PACKAGE__->has_many(
 __PACKAGE__->has_many(
     cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
 );
+__PACKAGE__->has_many(
+    year2001_cds => 'DBICTest::Schema::CD', undef,
+    { where => { year => 2001} },
+);
 
 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
diff --git a/t/prefetch/relationship_where_attr.t b/t/prefetch/relationship_where_attr.t
new file mode 100644 (file)
index 0000000..c0e2014
--- /dev/null
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+my $schema = DBICTest->init_schema();
+
+{
+  my $artist_with_year2001_cds = $schema->resultset('Artist')->find(1);
+  is $artist_with_year2001_cds->year2001_cds->count, 1, 'artist has one cd from 2001 without prefetching';
+}
+
+{
+  my $artist_with_year2001_cds = $schema->resultset('Artist')->find(1, { prefetch => 'year2001_cds' });
+  is $artist_with_year2001_cds->year2001_cds->count, 1, 'artist has one cd from 2001 with prefetching';
+}
+
+done_testing;