[Bast-commits] r7640 - in DBIx-Class/0.08/branches/extended_rels/t:
lib/DBICTest/Schema relationship
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Sat Sep 12 10:11:41 GMT 2009
Author: ribasushi
Date: 2009-09-12 10:11:41 +0000 (Sat, 12 Sep 2009)
New Revision: 7640
Added:
DBIx-Class/0.08/branches/extended_rels/t/relationship/custom.t
Modified:
DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Artist.pm
DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Track.pm
DBIx-Class/0.08/branches/extended_rels/t/relationship/core.t
Log:
Reshape initial tests
Modified: DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Artist.pm
===================================================================
--- DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Artist.pm 2009-09-12 03:26:37 UTC (rev 7639)
+++ DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Artist.pm 2009-09-12 10:11:41 UTC (rev 7640)
@@ -46,11 +46,11 @@
__PACKAGE__->has_many(
cds_80s => 'DBICTest::Schema::CD',
sub {
- my ( $rs, $self, $foreign ) = @_;
+ my ( $self_alias, $rel_alias, $self_rsrc, $rel_name ) = @_;
return {
- "${foreign}.artist" => "${self}.artistid",
- "${foreign}.year" => { '>', "1979" },
- "${foreign}.year" => { '<', "1990" }
+ "${rel_alias}.artist" => \ "${self_alias}.artistid",
+ "${rel_alias}.year" => { '>', "1979" },
+ "${rel_alias}.year" => { '<', "1990" }
};
}
);
Modified: DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Track.pm
===================================================================
--- DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Track.pm 2009-09-12 03:26:37 UTC (rev 7639)
+++ DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Track.pm 2009-09-12 10:11:41 UTC (rev 7640)
@@ -50,4 +50,16 @@
__PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' );
__PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' );
+__PACKAGE__->might_have (
+ 'next_track',
+ __PACKAGE__,
+ sub {
+ my ( $self_alias, $rel_alias, $self_rsrc, $rel_name ) = @_;
+ return {
+ "${self_alias}.cd" => \ "${rel_alias}.cd",
+ "${self_alias}.position" => { '<', \ "${rel_alias}.position" },
+ };
+ },
+);
+
1;
Modified: DBIx-Class/0.08/branches/extended_rels/t/relationship/core.t
===================================================================
--- DBIx-Class/0.08/branches/extended_rels/t/relationship/core.t 2009-09-12 03:26:37 UTC (rev 7639)
+++ DBIx-Class/0.08/branches/extended_rels/t/relationship/core.t 2009-09-12 10:11:41 UTC (rev 7640)
@@ -309,15 +309,4 @@
$cds = $schema->resultset("CD")->search({ 'me.cdid' => 5 }, { join => { single_track => { cd => {} } } });
is($cds->count, 1, "subjoins under left joins force_left (hashref)");
-$artist = $schema->resultset("Artist")->create({ name => 'Michael Jackson' });
-foreach my $year (1975..1985) {
- $artist->create_related('cds', { year => $year, title => 'Compilation from ' . $year });
-}
-
-my @cds_80s = $artist->cds_80s;
-
-is(@cds_80s, 6, '6 80s cds found');
-
-map { ok($_->year < 1990 && $_->year > 1979) } @cds_80s;
-
done_testing;
Added: DBIx-Class/0.08/branches/extended_rels/t/relationship/custom.t
===================================================================
--- DBIx-Class/0.08/branches/extended_rels/t/relationship/custom.t (rev 0)
+++ DBIx-Class/0.08/branches/extended_rels/t/relationship/custom.t 2009-09-12 10:11:41 UTC (rev 7640)
@@ -0,0 +1,45 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+
+my $artist = $schema->resultset("Artist")->create({ name => 'Michael Jackson' });
+foreach my $year (1975..1985) {
+ $artist->create_related('cds', { year => $year, title => 'Compilation from ' . $year });
+}
+
+my @cds_80s = $artist->cds_80s;
+
+is(@cds_80s, 6, '6 80s cds found');
+
+map { ok($_->year < 1990 && $_->year > 1979) } @cds_80s;
+
+
+
+
+my @last_track_ids;
+for my $cd ($schema->resultset('CD')->search ({}, { order_by => 'cdid'})->all) {
+ push @last_track_ids, $cd->tracks
+ ->search ({}, { order_by => { -desc => 'position'} })
+ ->get_column ('trackid')
+ ->next;
+}
+
+my $last_tracks = $schema->resultset('Track')->search (
+ {'next_track.trackid' => undef},
+ { join => 'next_track', order_by => 'me.cd' },
+);
+
+is_deeply (
+ [$last_tracks->get_column ('trackid')->all],
+ \@last_track_ids,
+ 'last group-entry via self-join works',
+);
+
+done_testing;
More information about the Bast-commits
mailing list