aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2018-03-15 10:57:31 +0000
committerDave Arter <davea@mysociety.org>2018-03-15 11:19:41 +0000
commite1f7ee00b13ca71a2d2197b32dae73d8f703ba6c (patch)
treecc22f277894d7c935acc035c04665277e1f94f22
parent40a3bfb7566b02db2eb6019adcbefeaa19ffb42f (diff)
Fix JSON-encoding crash on /report/ajax
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm8
-rw-r--r--t/app/controller/report_display.t6
2 files changed, 13 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 7062f481f..df4dc5f77 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -221,9 +221,15 @@ sub format_problem_for_display : Private {
if ( $c->stash->{ajax} ) {
$c->res->content_type('application/json; charset=utf-8');
+
+ # encode_json doesn't like DateTime objects, so strip them out
+ my $report_hashref = $c->cobrand->problem_as_hashref( $problem, $c );
+ delete $report_hashref->{created};
+ delete $report_hashref->{confirmed};
+
my $content = encode_json(
{
- report => $c->cobrand->problem_as_hashref( $problem, $c ),
+ report => $report_hashref,
updates => $c->cobrand->updates_as_hashref( $problem, $c ),
}
);
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index 605371ed7..17b9180c1 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -115,6 +115,12 @@ subtest "duplicate reports are signposted correctly" => sub {
$report2->update;
};
+subtest "test /report/ajax" => sub {
+ my $json = $mech->get_ok_json( "/report/ajax/$report_id" );
+ is $json->{report}->{title}, "Test 2", "correct title";
+ is $json->{report}->{state}, "confirmed", "correct state";
+};
+
subtest "test a good report" => sub {
$mech->get_ok("/report/$report_id");
is $mech->uri->path, "/report/$report_id", "at /report/$report_id";