Skip to content

Commit

Permalink
add version restriction to release data
Browse files Browse the repository at this point in the history
Now we can get a single row from the release data table
  • Loading branch information
preaction committed Apr 21, 2018
1 parent fec3d0e commit 63b0f6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/CPAN/Testers/Schema/ResultSet/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ our $VERSION = '0.023';
=head1 SYNOPSIS
my $rs = $schema->resultset( 'Release' );
$rs->by_dist( 'My-Dist' );
$rs->by_dist( 'My-Dist', '0.001' );
$rs->by_author( 'PREACTION' );
$rs->since( '2016-01-01T00:00:00' );
$rs->maturity( 'stable' );
Expand All @@ -28,14 +28,19 @@ use CPAN::Testers::Schema::Base 'ResultSet';
=method by_dist
$rs = $rs->by_dist( 'My-Dist' );
$rs = $rs->by_dist( 'My-Dist', '0.001' );
Add a dist constraint to the query, replacing any previous dist
constraints.
Add a dist constraint to the query (with optional version), replacing
any previous dist constraints.
=cut

sub by_dist( $self, $dist ) {
return $self->search( { 'me.dist' => $dist } );
sub by_dist( $self, $dist, $version = undef ) {
my %search = ( 'me.dist' => $dist );
if ( $version ) {
$search{ 'me.version' } = $version;
}
return $self->search( \%search );
}

=method by_author
Expand Down
6 changes: 6 additions & 0 deletions t/resultset/release.t
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ subtest 'by_dist' => sub {
or diag explain [ $rs->all ];
};

subtest 'version' => sub {
my $rs = $schema->resultset( 'Release' )->by_dist( 'My-Dist', '1.001' );
$rs->result_class( 'DBIx::Class::ResultClass::HashRefInflator' );
is_deeply [ $rs->all ], [ $data{Release}->@[0] ], 'get 1.001 of My-Dist'
or diag explain [ $rs->all ];
};
};

subtest 'by_author' => sub {
Expand Down

0 comments on commit 63b0f6e

Please sign in to comment.