From e6a01721c87b7e3463093e64e97e08ed96f54bce Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Wed, 16 Nov 2016 11:36:48 +0000 Subject: If a problem has duplicates, display them on its detail page --- perllib/FixMyStreet/DB/Result/Problem.pm | 12 ++++++++ t/app/controller/report_inspect.t | 6 +++- t/app/model/problem.t | 11 +++++++ templates/web/base/report/_inspect.html | 52 ++++++++++++++++++-------------- 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index bb21fcc11..b7573d994 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -181,6 +181,7 @@ use namespace::clean -except => [ 'meta' ]; use Utils; use FixMyStreet::Map::FMS; use LWP::Simple qw($ua); +use RABX; my $IM = eval { require Image::Magick; @@ -1044,4 +1045,15 @@ has duplicate_of => ( }, ); +has duplicates => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + my $rabx_id = RABX::serialise( $self->id ); + my @duplicates = $self->result_source->schema->resultset('Problem')->search({ extra => { like => "\%duplicate_of,$rabx_id%" } })->all; + return \@duplicates; + }, +); + 1; diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index 9a62b1eb7..b4d6636b9 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -93,7 +93,7 @@ FixMyStreet::override_config { $mech->content_lacks('Invalid location'); }; - subtest "test duplicate report is shown" => sub { + subtest "test duplicate reports are shown" => sub { my ($report2) = $mech->create_problems_for_body(1, $oxon->id, 'The other report is a duplicate of this one', { category => $report->category, cobrand => 'fixmystreet', areas => ',2237,2420', whensent => \'current_timestamp', @@ -107,6 +107,10 @@ FixMyStreet::override_config { $mech->get_ok("/report/$report_id"); $mech->content_contains($report2->title); + my $report2_id = $report2->id; + $mech->get_ok("/report/$report2_id"); + $mech->content_contains($report->title); + $report->unset_extra_metadata('duplicate_of'); $report->state($old_state); $report->update; diff --git a/t/app/model/problem.t b/t/app/model/problem.t index bd7d0e55c..1130078c0 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -763,6 +763,17 @@ subtest 'check response templates' => sub { is $problem->response_templates, 2, 'Global and pothole templates returned'; }; +subtest 'check duplicate reports' => sub { + my ($problem1, $problem2) = $mech->create_problems_for_body(2, $body_ids{2651}, 'TITLE'); + $problem1->set_extra_metadata(duplicate_of => $problem2->id); + $problem1->state('duplicate'); + $problem1->update; + + is $problem1->duplicate_of->title, $problem2->title, 'problem1 returns correct problem from duplicate_of'; + is scalar @{ $problem2->duplicates }, 1, 'problem2 has correct number of duplicates'; + is $problem2->duplicates->[0]->title, $problem1->title, 'problem2 includes problem1 in duplicates'; +}; + END { $problem->comments->delete if $problem; $problem->delete if $problem; diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html index d5df3d42e..3479058c3 100644 --- a/templates/web/base/report/_inspect.html +++ b/templates/web/base/report/_inspect.html @@ -64,28 +64,36 @@ [% END %] [% IF permissions.report_inspect %] -

- - [%# XXX this is duplicated from admin/report_edit.html, should be refactored %] - -

-
- - Which report is it a duplicate of? - -
+

+ + [%# XXX this is duplicated from admin/report_edit.html, should be refactored %] + +

+
+ + [% loc('Which report is it a duplicate of?') %] + +
+ [% IF problem.duplicates.size %] +

[% loc('Duplicates') %]

+ + [% END %] [% END %] -- cgit v1.2.3