Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/GADS/Import.pm
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ sub _build_fields
my @fields;
my $column_id = $self->layout->column_id;

my $col_count = 0;
foreach my $field (@$fields_in)
{
$col_count++;
if (
(
($self->update_unique && $self->update_unique == $column_id->id) ||
Expand Down Expand Up @@ -298,6 +300,8 @@ sub _build_fields
$search->{name} = $field if !$self->short_names;
$search->{name_short} = $field if $self->short_names;
my $f_rs = $self->schema->resultset('Layout')->search($search);
error __x"Empty field name in import headings (Column {column})", column => $col_count
if $field =~ /^\s*$/;
error __x"Layout has more than one field named {name}", name => $field
if $f_rs->count > 1;
error __x"Field '{name}' in import headings not found in table", name => $field
Expand Down
16 changes: 15 additions & 1 deletion t/014_import.t
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ my @tests = (
count_on => 1,
count_off => 1,
},
{
data => "string1, ,integer1\nFoo,Bar,123",
option => undef,
error => qr\Empty field name\,
count_on => 1,
count_off => 1,
},
{
data => "string1\nString content",
option => 'dry_run',
Expand Down Expand Up @@ -228,7 +235,14 @@ foreach my $test (@tests)

my $test_name = defined $test->{option} ? "with option $test->{option} set to $status" : "with no options";
is($records->count, 0, "No records before import for test $test_name");
$import->process;

try { $import->process; };
if ($test->{error})
{
like($@, $test->{error}, "Got expected import error");
next;
}

$records->clear;
is($records->count, $test->{"count_$status"}, "Correct record count on import for test $test_name");

Expand Down
Loading