Skip to content

Commit

Permalink
show a clearer message to the user when we can not find the parent we…
Browse files Browse the repository at this point in the history
…ll on plate upload, add tests for new error message
  • Loading branch information
sajp committed Sep 5, 2012
1 parent 3ad841d commit 3f776dd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/LIMS2/Model/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package LIMS2::Model::Util;
use strict;
use warnings FATAL => 'all';

use Try::Tiny;
use LIMS2::Exception::Validation;
use Sub::Exporter -setup => {
exports => [ qw( sanitize_like_expr well_id_for ) ]
};
Expand All @@ -28,7 +30,13 @@ sub sanitize_like_expr {
sub well_id_for {
my ( $model, $data ) = @_;

return $model->retrieve_well($data)->id;
my $well = try { $model->retrieve_well($data) }
catch {
LIMS2::Exception::Validation->throw(
'Can not find parent well ' . $data->{plate_name} . '[' . $data->{well_name} . ']' );
};

return $well->id;
}

1;
Expand Down
28 changes: 26 additions & 2 deletions t/80-plate_upload.t
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ ok $mech->submit_form(
{
note( "Invalid well data" );
my $test_file = File::Temp->new or die('Could not create temp test file ' . $!);
$test_file->print("well_name,parent_plate,parent_well,cell_line\n"
$test_file->print("well_name,parent_plate,parent_well,cell_line\n"
. "BLAH,MOHFAQ001_A_2,A01,cell_line_foo");
$test_file->seek( 0, 0 );

Expand All @@ -214,10 +214,34 @@ ok $mech->submit_form(
, '...throws error parameter validation failed for well_name';
}

{
note( "Invalid parent well" );
my $test_file = File::Temp->new or die('Could not create temp test file ' . $!);
$test_file->print("well_name,parent_plate,parent_well,cell_line\n"
. "A01,MOHFAZ001_A_2,A01,cell_line_foo");
$test_file->seek( 0, 0 );

$mech->get_ok( '/user/plate_upload_step2?process_type=first_electroporation' );
$mech->title_is('Plate Upload 2');
ok my $res = $mech->submit_form(
form_id => 'plate_create',
fields => {
plate_name => 'EPTEST',
datafile => $test_file->filename
},
button => 'create_plate'
), 'submit form with well data file with invalid parent well data';

ok $res->is_success, '...response is_success';
is $res->base->path, '/user/plate_upload_step2', '... stays on same page';
like $res->content, qr/Error encountered while creating plate: Can not find parent well MOHFAZ/
, '...throws error can not find parent well';
}

{
note( "Successful plate create" );
my $test_file = File::Temp->new or die('Could not create temp test file ' . $!);
$test_file->print("well_name,parent_plate,parent_well,cell_line\n"
$test_file->print("well_name,parent_plate,parent_well,cell_line\n"
. "A01,MOHFAQ0001_A_2,A01,cell_line_foo");
$test_file->seek( 0, 0 );

Expand Down

0 comments on commit 3f776dd

Please sign in to comment.