Skip to content

Commit

Permalink
Template Toolkit works better with arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcam committed Jun 5, 2024
1 parent 5efbb3a commit 447b6dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/npg/model/instrument.pm
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ sub recent_staging_volumes {
push @volumes, {'volume' => $area, $date_field => $date};
}

return @volumes;
return \@volumes;
}

sub does_sequencing {
Expand Down Expand Up @@ -745,12 +745,12 @@ npg::model::instrument
=head2 fc_slots2blocking_runs - a hash reference mapping instrument flowcell slots to blocking runs; tags for slots are used as keys
=head2 recent_staging_volumes - returns a list of hash references containing
=head2 recent_staging_volumes - returns an array of hash references containing
information about the volumes this instrument recently transferred data to.
The list might be empty. It is guaranteed not to contain more than two members.
The array might be empty. It is guaranteed not to contain more than two members.
Under the 'volume' key each hash has the name of the volume, under the 'maxdate'
key - the most recent date this volume was used by this instrument. The first
list member describes the volume that was used most recently.
array member describes the volume that was used most recently.
=head2 does_sequencing - returns true is the instrument does sequencing, false otherwise
Expand Down
14 changes: 7 additions & 7 deletions t/10-model-instrument.t
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ subtest 'recent staging volumes list' => sub {
util => $util,
id_instrument => 3,
});
my @volumes = $model->recent_staging_volumes();
my @volumes = @{$model->recent_staging_volumes()};
is (@volumes, 1, 'one record is returned');
is ($volumes[0]->{'volume'}, q[esa-sv-20201215-03],
qq[volume name for a single run that is associated with the "$status" status]);
Expand All @@ -443,15 +443,15 @@ subtest 'recent staging volumes list' => sub {
util => $util,
id_instrument => 14,
});
is (scalar $model->recent_staging_volumes(), 0,
is (scalar @{$model->recent_staging_volumes()}, 0,
'empty list since no glob is available for a run that is associated with ' .
qq[the "$status" status]);

$model = npg::model::instrument->new({
util => $util,
id_instrument => 13,
});
@volumes = $model->recent_staging_volumes();
@volumes = @{$model->recent_staging_volumes()};
is (@volumes, 1, 'one record is returned');
is ($volumes[0]->{'volume'}, 'esa-sv-20201215-02', 'volume name is correct');
is ($volumes[0]->{'maxdate'}, '2007-06-05', 'the date is correct');
Expand All @@ -463,7 +463,7 @@ subtest 'recent staging volumes list' => sub {
util => $util,
id_instrument => 13,
});
@volumes = $model->recent_staging_volumes();
@volumes = @{$model->recent_staging_volumes()};
is ($volumes[0]->{'volume'}, $new_glob, 'a full glob is returned');

$new_glob = q[/{export,nfs}];
Expand All @@ -473,7 +473,7 @@ subtest 'recent staging volumes list' => sub {
util => $util,
id_instrument => 13,
});
@volumes = $model->recent_staging_volumes();
@volumes = @{$model->recent_staging_volumes()};
is ($volumes[0]->{'volume'}, $new_glob, 'a full glob is returned');

$update = q[update run set folder_path_glob='' where id_run=15];
Expand All @@ -482,7 +482,7 @@ subtest 'recent staging volumes list' => sub {
util => $util,
id_instrument => 13,
});
@volumes = $model->recent_staging_volumes();
@volumes = @{$model->recent_staging_volumes()};
is (@volumes, 0, 'an empty list is returned for a zero length glob');

$update = q[update run_status set id_run_status_dict=2 where ] .
Expand All @@ -501,7 +501,7 @@ subtest 'recent staging volumes list' => sub {
util => $util,
id_instrument => 3,
});
@volumes = $model->recent_staging_volumes();
@volumes = @{$model->recent_staging_volumes()};
is (@volumes, 2, 'data for two volumes');
is ($volumes[1]->{'volume'}, q[esa-sv-20201215-03], 'previous volume');
is ($volumes[1]->{'maxdate'}, '2007-06-05', 'the date is correct');
Expand Down

0 comments on commit 447b6dd

Please sign in to comment.