Skip to content

Commit

Permalink
Merge ac325aa into e8c63b3
Browse files Browse the repository at this point in the history
  • Loading branch information
nephila-nacrea committed Jul 1, 2022
2 parents e8c63b3 + ac325aa commit 01b7dbe
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Inspector dropdown list doesn't show anonymised users, removing blank options #3873
- Fix report unassignment so it works for users who did not create the report #3903
- [Open311] External code removal is not a change.
- Trim whitespace on extra status codes for response templates
- Accessibility improvements:
- The "skip map" link on /around now has new wording. #3794
- Improve visual contrast of pagination links. #3794
Expand Down
25 changes: 24 additions & 1 deletion perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,28 @@ __PACKAGE__->has_many(

__PACKAGE__->many_to_many( contacts => 'contact_response_templates', 'contact' );

# You can replace this text with custom code or comments, and it will be preserved on regeneration
use Utils;

# Trim whitespace for external_status_code

sub new {
my ( $self, $attrs ) = @_;

$attrs->{external_status_code}
= Utils::trim_text( $attrs->{external_status_code} )
if $attrs->{external_status_code};

return $self->next::method($attrs);
}

sub set_column {
my ( $self, $column, $new_value ) = @_;

if ( $column eq 'external_status_code' ) {
$new_value = Utils::trim_text($new_value);
}

$self->next::method( $column, $new_value );
};

1;
54 changes: 53 additions & 1 deletion t/app/model/responsetemplate.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $t2->add_to_contacts($c2);

my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $body->id ] } )->all;

subtest 'by_categories returns allresponse templates grouped by category' => sub {
subtest 'by_categories returns all response templates grouped by category' => sub {
my $templates = FixMyStreet::DB->resultset('ResponseTemplate')->by_categories(\@contacts, body_id => $body->id);
my $potholes = JSON::MaybeXS->new->decode($templates->{Potholes});
my $graffiti = JSON::MaybeXS->new->decode($templates->{Graffiti});
Expand All @@ -25,6 +25,58 @@ subtest 'by_categories returns allresponse templates grouped by category' => sub
is scalar @$graffiti, 2, 'Graffiti has 2 templates';
is $graffiti->[0]->{state}, 'investigating', 'Graffiti first template has right state';
is $potholes->[0]->{id}, 'Text 1 ⛄', 'Pothole first template has right text';
is $graffiti->[1]->{id}, $potholes->[1]->{id},
'3rd template applies to both graffiti and potholes';
# is $graffiti->[1]->external_status_code, '060',
# 'Whitespace trimmed from external_status_code';
};

subtest 'Trim whitespace on external_status_code' => sub {
my $t_whitespace
= FixMyStreet::DB->resultset('ResponseTemplate')->create(
{ body_id => $body->id,
title => 'Title',
text => 'Text',
external_status_code => "      \t\n060\n\t     ",
}
);

note 'Create template:';
is $t_whitespace->external_status_code, '060',
'external_status_code correctly munged';

note 'Update with external_status_code arg:';
$t_whitespace->update( { external_status_code => ' 171 ' } );
$t_whitespace->discard_changes;
is $t_whitespace->external_status_code, '171',
'external_status_code correctly munged';

note 'Unset with external_status_code arg:';
$t_whitespace->update( { external_status_code => undef } );
$t_whitespace->discard_changes;
is $t_whitespace->external_status_code, undef,
'external_status_code unset';

note 'Set external_status_code followed by call to update:';
$t_whitespace->external_status_code(' 282 ');
$t_whitespace->update;
$t_whitespace->discard_changes;
is $t_whitespace->external_status_code, '282',
'external_status_code correctly munged';

note 'Unset external_status_code followed by call to update:';
$t_whitespace->external_status_code(undef);
$t_whitespace->update;
$t_whitespace->discard_changes;
is $t_whitespace->external_status_code, undef,
'external_status_code unset';

note 'Set external_status_code AND pass arg to update:';
$t_whitespace->external_status_code(' 393 ');
$t_whitespace->update( { external_status_code => ' 404 ' } );
$t_whitespace->discard_changes;
is $t_whitespace->external_status_code, '404',
'arg passed to update takes precedence';
};

done_testing;

0 comments on commit 01b7dbe

Please sign in to comment.