Skip to content

Commit

Permalink
Merge branch 'issues/commercial/1917-fix-template-unicode'
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jun 10, 2020
2 parents 4767816 + f706b89 commit ffb88ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- bin/update-schema PostgreSQL 12 compatibility. #3043
- Make sure category shown in all its groups when reporting.
- Do not remove any devolved contacts.
- Fix double encoding of per-category templates.
- Admin improvements:
- Display user name/email for contributed as reports. #2990
- Interface for enabling anonymous reports for certain categories. #2989
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Roles/ContactExtra.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ sub by_categories {
|| (grep { $_->contact_id == $contact->get_column('id') } $_->$join_table)
} @results;
@ts = $rs->map_extras(@ts);
$extras{$contact->category} = encode_json(\@ts);
$extras{$contact->category} = JSON::XS->new->encode(\@ts);
}

return \%extras;
Expand Down
8 changes: 5 additions & 3 deletions t/app/model/responsetemplate.t
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use utf8;
use FixMyStreet::TestMech;
use JSON::MaybeXS;

Expand All @@ -7,7 +8,7 @@ my $area_id = 2651;
my $body = $mech->create_body_ok($area_id, 'Edinburgh Council');
my $c1 = $mech->create_contact_ok(category => 'Potholes', body_id => $body->id, email => 'p');
my $c2 = $mech->create_contact_ok(category => 'Graffiti', body_id => $body->id, email => 'g');
my $t1 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 1", text => "Text 1" });
my $t1 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 1", text => "Text 1" });
my $t2 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 2", text => "Text 2", state => 'investigating' });
my $t3 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 3", text => "Text 3" });
$t1->add_to_contacts($c1);
Expand All @@ -17,12 +18,13 @@ my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { bod

subtest 'by_categories returns allresponse templates grouped by category' => sub {
my $templates = FixMyStreet::DB->resultset('ResponseTemplate')->by_categories(\@contacts, body_id => $body->id);
my $potholes = decode_json($templates->{Potholes});
my $graffiti = decode_json($templates->{Graffiti});
my $potholes = JSON::MaybeXS->new->decode($templates->{Potholes});
my $graffiti = JSON::MaybeXS->new->decode($templates->{Graffiti});

is scalar @$potholes, 2, 'Potholes have 2 templates';
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';
};

done_testing;

0 comments on commit ffb88ce

Please sign in to comment.