From 447b6dd567df4654fe22b90ad28b1d258709a050 Mon Sep 17 00:00:00 2001 From: Marina Gourtovaia Date: Wed, 5 Jun 2024 12:22:22 +0100 Subject: [PATCH] Template Toolkit works better with arrays --- lib/npg/model/instrument.pm | 8 ++++---- t/10-model-instrument.t | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/npg/model/instrument.pm b/lib/npg/model/instrument.pm index a9074ab3..6b6ec03d 100644 --- a/lib/npg/model/instrument.pm +++ b/lib/npg/model/instrument.pm @@ -418,7 +418,7 @@ sub recent_staging_volumes { push @volumes, {'volume' => $area, $date_field => $date}; } - return @volumes; + return \@volumes; } sub does_sequencing { @@ -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 diff --git a/t/10-model-instrument.t b/t/10-model-instrument.t index 6c75c273..44a21f1f 100644 --- a/t/10-model-instrument.t +++ b/t/10-model-instrument.t @@ -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]); @@ -443,7 +443,7 @@ 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]); @@ -451,7 +451,7 @@ subtest 'recent staging volumes list' => sub { 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'); @@ -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}]; @@ -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]; @@ -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 ] . @@ -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');