Skip to content

Commit

Permalink
MBS-12351: Also trim space only disambiguations
Browse files Browse the repository at this point in the history
The transform was not being applied on spaces-only
disambiguation fields, because FormHandler considers it
empty. As such, I added validate_when_empty to enforce
always running the transform on the comment field.

This broke the test adding a rel, because we weren't entering
the comment field. That seemed weird to begin with (we are also
not changing name and sort name, yet we list them) so adding it here.
  • Loading branch information
reosarevok committed May 30, 2022
1 parent 75177fa commit 311bb6b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/MusicBrainz/Server/Form/Field/Comment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ extends 'HTML::FormHandler::Field::Text';

has '+maxlength' => ( default => 255 );
has '+not_nullable' => ( default => 1 );
has '+validate_when_empty' => (
default => 1
);

apply ([
{
Expand Down
35 changes: 35 additions & 0 deletions t/lib/t/MusicBrainz/Server/Controller/Artist/Create.pm
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,41 @@ test 'MBS-10976: Private use characters U+E000..U+F8FF are allowed' => sub {
);
};

test 'MBS-12351: Space-only disambiguations are trimmed properly' => sub {
my $test = shift;
my $mech = $test->mech;

prepare_test($test);

$mech->get_ok('/artist/create');

my @edits = capture_edits {
$mech->submit_form_ok({
with_fields => {
'edit-artist.name' => 'Testy',
'edit-artist.sort_name' => 'Testy',
'edit-artist.comment' => ' ',
},
},
'The form returned a 2xx response code')
} $test->c;

ok(
$mech->uri =~ $artist_page_regexp,
'The user is redirected to the artist page after entering the edit',
);

is(@edits, 1, 'The edit was entered');

my $edit = shift(@edits);

is(
$edit->data->{comment},
'',
'The submitted comment is empty',
);
};

sub prepare_test {
my $test = shift;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ test 'Test adding a relationship' => sub {
$mech->post('/artist/745c079d-374e-4436-9448-da92dedef3ce/edit', {
'edit-artist.name' => 'Test Artist',
'edit-artist.sort_name' => 'Artist, Test',
'edit-artist.comment' => 'Yet Another Test Artist',
'edit-artist.type_id' => '1',
'edit-artist.gender_id' => '1',
'edit-artist.period.ended' => '1',
Expand Down

0 comments on commit 311bb6b

Please sign in to comment.