diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 5 | ||||
-rw-r--r-- | t/app/controller/report_inspect.t | 19 |
3 files changed, 25 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index a9d171d33..cd42e89a4 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -345,6 +345,9 @@ sub inspect : Private { if ( $problem->state eq 'hidden' ) { $problem->get_photoset->delete_cached; } + if ( $problem->state ne 'duplicate' ) { + $problem->unset_extra_metadata('duplicate_of'); + } if ( $problem->state ne $old_state ) { $c->forward( '/admin/log_edit', [ $problem->id, 'problem', 'state_change' ] ); } diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index c63e6c881..bb21fcc11 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -1037,8 +1037,9 @@ has duplicate_of => ( lazy => 1, default => sub { my $self = shift; - my $duplicate_of = $self->get_extra_metadata("duplicate_of"); - return unless defined $duplicate_of; + return unless $self->state eq 'duplicate'; + my $duplicate_of = int($self->get_extra_metadata("duplicate_of") || 0); + return unless $duplicate_of; return $self->result_source->schema->resultset('Problem')->search({ id => $duplicate_of })->first; }, ); diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index efb32d116..9a62b1eb7 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -93,6 +93,25 @@ FixMyStreet::override_config { $mech->content_lacks('Invalid location'); }; + subtest "test duplicate report is 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', + latitude => 51.847694, longitude => -1.355909, + }); + my $old_state = $report->state; + $report->set_extra_metadata('duplicate_of' => $report2->id); + $report->state('duplicate'); + $report->update; + + $mech->get_ok("/report/$report_id"); + $mech->content_contains($report2->title); + + $report->unset_extra_metadata('duplicate_of'); + $report->state($old_state); + $report->update; + }; + foreach my $test ( { type => 'report_edit_priority', priority => 1 }, { type => 'report_edit_category', category => 1 }, |