aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm16
-rw-r--r--t/app/controller/admin.t12
2 files changed, 13 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 651dd147d..d3b6a39ee 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -228,7 +228,9 @@ sub bodies : Path('bodies') : Args(0) {
my $params = $c->forward('body_params');
my $body = $c->model('DB::Body')->create( $params );
- foreach ($c->req->params->{area_ids}) {
+ my $area_ids = $c->req->params->{area_ids};
+ $area_ids = [ $area_ids ] unless ref $area_ids;
+ foreach (@$area_ids) {
$c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } );
}
@@ -362,7 +364,9 @@ sub update_contacts : Private {
$c->stash->{body}->update( $params );
my @current = $c->stash->{body}->body_areas->all;
my %current = map { $_->area_id => 1 } @current;
- foreach ($c->req->params->{area_ids}) {
+ my $area_ids = $c->req->params->{area_ids};
+ $area_ids = [ $area_ids ] unless ref $area_ids;
+ foreach (@$area_ids) {
$c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } );
delete $current{$_};
}
@@ -412,9 +416,11 @@ sub lookup_body : Private {
unless $body;
$c->stash->{body} = $body;
- my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->body_areas->first->area_id);
- if ($example_postcode && ! ref $example_postcode) {
- $c->stash->{example_pc} = $example_postcode;
+ if ($body->body_areas->first) {
+ my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->body_areas->first->area_id);
+ if ($example_postcode && ! ref $example_postcode) {
+ $c->stash->{example_pc} = $example_postcode;
+ }
}
return 1;
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index d8b721ca9..fecc5b10f 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -258,11 +258,7 @@ subtest 'check open311 configuring' => sub {
$mech->content_contains('Council contacts configured via Open311');
$mech->content_contains('Configuration updated - contacts will be generated automatically later');
- my $open311 =
- FixMyStreet::App->model('DB::Body')->search( { 'body_areas.area_id' => 2650 }, { join => 'body_areas' } );
-
- is $open311->count, 1, 'only one configuration';
- my $conf = $open311->first;
+ my $conf = FixMyStreet::App->model('DB::Body')->find( 2650 );
is $conf->endpoint, 'http://example.com/open311', 'endpoint configured';
is $conf->api_key, 'api key', 'api key configured';
is $conf->jurisdiction, 'mySociety', 'jurisdiction configures';
@@ -282,11 +278,7 @@ subtest 'check open311 configuring' => sub {
$mech->content_contains('Configuration updated');
- $open311 =
- FixMyStreet::App->model('DB::Body')->search( { 'body_areas.area_id' => 2650 }, { join => 'body_areas' } );
-
- is $open311->count, 1, 'only one configuration';
- $conf = $open311->first;
+ $conf = FixMyStreet::App->model('DB::Body')->find( 2650 );
is $conf->endpoint, 'http://example.org/open311', 'endpoint updated';
is $conf->api_key, 'new api key', 'api key updated';
is $conf->jurisdiction, 'open311', 'jurisdiction configures';