aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2018-10-15 16:23:58 +0100
committerDave Arter <davea@mysociety.org>2018-10-17 12:59:41 +0100
commit08e335ce05c81db337f3f7623e1e3fe734546ce9 (patch)
tree3c2fcbc82e2ca735e03717a6ad23b51be1c4dbb2
parenta1122f6d8b3cd4fe35724ab5b4d234ee33670e87 (diff)
Update areas when moving report pin
The change in report_inspect.t from WODC to Oxford City was necessary because moving reports to a location not in Mock::MapIt was resulting in an empties bodies_str in the "test category/body changes" test. Fixes #2181.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm3
-rw-r--r--t/Mock/MapIt.pm1
-rw-r--r--t/app/controller/report_inspect.t23
4 files changed, 23 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cd474a6cb..5046eacf7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@
- Add perl 5.26/5.28 support.
- Fix subcategory issues when visiting /report/new directly #2276
- Give superusers access to update staff dropdowns. #2286
+ - Update report areas when moving its location. #2181
- Development improvements:
- Add cobrand hook for dashboard viewing permission. #2285
- Have body.url work in hashref lookup. #2284
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 504de19ca..8ccc5b8d3 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -1082,6 +1082,7 @@ sub report_edit_location : Private {
# this lookup is bad. So let's save the stash and restore it after the
# comparison.
my $safe_stash = { %{$c->stash} };
+ $c->stash->{fetch_all_areas} = 1;
$c->forward('/council/load_and_check_areas', []);
$c->forward('/report/new/setup_categories_and_bodies');
my %allowed_bodies = map { $_ => 1 } @{$problem->bodies_str_ids};
@@ -1091,6 +1092,8 @@ sub report_edit_location : Private {
return unless $bodies_match;
$problem->latitude($c->stash->{latitude});
$problem->longitude($c->stash->{longitude});
+ my $areas = $c->stash->{all_areas_mapit};
+ $problem->areas( ',' . join( ',', sort keys %$areas ) . ',' );
}
return 1;
}
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm
index dc23b9ae2..0b9d398e8 100644
--- a/t/Mock/MapIt.pm
+++ b/t/Mock/MapIt.pm
@@ -32,6 +32,7 @@ my @PLACES = (
[ 'GL50 2PR', 51.896268, -2.093063, 2226, 'Gloucestershire County Council', 'CTY', 2326, 'Cheltenham Borough Council', 'DIS', 4544, 'Lansdown', 'DIW', 143641, 'Lansdown and Park', 'CED' ],
[ '?', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ],
[ 'OX20 1SZ', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ],
+ [ 'OX16 9UP', 52.038712, -1.346397, 2237, 'Oxfordshire County Council', 'CTY', 2419, 'Cherwell District Council', 'DIS', 151767, "Banbury, Calthorpe & Easington", "DIW" ],
[ 'BR1 3UH', 51.4021, 0.01578, 2482, 'Bromley Council', 'LBO' ],
[ 'BR1 3UH', 51.402096, 0.015784, 2482, 'Bromley Council', 'LBO' ],
[ '?', 50.78301, -0.646929 ],
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 6e65c1336..e3ca33f0f 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -32,14 +32,14 @@ FixMyStreet::DB->resultset("ContactResponsePriority")->create({
contact => $contact3,
response_priority => $rp2,
});
-my $wodc = $mech->create_body_ok(2420, 'West Oxfordshire District Council');
-$mech->create_contact_ok( body_id => $wodc->id, category => 'Horses', email => 'horses@example.net' );
+my $oxfordcity = $mech->create_body_ok(2421, 'Oxford City Council');
+$mech->create_contact_ok( body_id => $oxfordcity->id, category => 'Horses', email => 'horses@example.net' );
my ($report, $report2, $report3) = $mech->create_problems_for_body(3, $oxon->id, 'Test', {
- category => 'Cows', cobrand => 'fixmystreet', areas => ',2237,2420',
+ category => 'Cows', cobrand => 'fixmystreet', areas => ',2237,2421,',
whensent => \'current_timestamp',
- latitude => 51.847693, longitude => -1.355908,
+ latitude => 51.754926, longitude => -1.256179,
});
my $report_id = $report->id;
my $report2_id = $report2->id;
@@ -153,6 +153,19 @@ FixMyStreet::override_config {
$mech->content_lacks('Invalid location');
};
+ subtest "test areas update when location changes" => sub {
+ $report->discard_changes;
+ my ($lat, $lon, $areas) = ($report->latitude, $report->longitude, $report->areas);
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({ button => 'save', with_fields => { latitude => 52.038712, longitude => -1.346397, include_update => undef } });
+ $mech->content_lacks('Invalid location');
+ $report->discard_changes;
+ is $report->areas, ",151767,2237,2419,", 'Areas set correctly';
+ $mech->submit_form_ok({ button => 'save', with_fields => { latitude => $lat, longitude => $lon, include_update => undef } });
+ $report->discard_changes;
+ is $report->areas, $areas, 'Areas reset correctly';
+ };
+
subtest "test duplicate reports are shown" => sub {
my $old_state = $report->state;
$report->set_extra_metadata('duplicate_of' => $report2->id);
@@ -761,7 +774,7 @@ FixMyStreet::override_config {
$report->discard_changes;
is $report->category, "Horses", "Report in correct category";
is $report->whensent, undef, "Report marked as unsent";
- is $report->bodies_str, $wodc->id, "Reported to WODC";
+ is $report->bodies_str, $oxfordcity->id, "Reported to Oxford City";
is $mech->uri->path, "/report/$report_id", "redirected to correct page";
is $mech->res->code, 200, "got 200 for final destination";