aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Day <steve@mysociety.org>2014-07-29 16:46:04 +0100
committerHakim Cassimally <hakim@mysociety.org>2014-07-31 11:17:07 +0000
commit0c254d386b2580bdcd2ffea43391acc1e682a6d4 (patch)
treeb72206ec087a1db50bc2cd7102b446882b486a4c
parent9a8fa132b6718b7f994476b4175f81fceebe337e (diff)
Replace from_council with from_body in SeeSomething cobrand
'from_council' was renamed to 'from_body' and turned into a relationship in b2aa34b Feb 2013, and the seesomething code was missed. Though the FMS::DB::Result::User object would (correctly) throw an error if an invalid method is called, *Catalyst* idea of a user object wraps this in a Catalyst::Authentication::Store::DBIx::Class which uses AUTOLOAD to delegate methods and swallows the error. e.g. this code always returns false, hence the code path is never run. (I think this is a bug and have opened: https://rt.cpan.org/Ticket/Display.html?id=97640 ) Added test case and (hopefully) corrected template, will need a check against site running copy with recent data to check that nothing looks squiffy. We also had to change the %council_details stash, which was based on the old code, not sure if suggested fix matches original intent, but looks plausible. (As discussed with @dracos @stevenday this is slightly repeated, and should arguably use ->{bodies} but that's a possible future FIXME)
-rw-r--r--perllib/FixMyStreet/Cobrand/SeeSomething.pm11
-rw-r--r--t/cobrand/seesomething.t39
-rw-r--r--templates/web/seesomething/admin/stats.html2
3 files changed, 46 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/Cobrand/SeeSomething.pm b/perllib/FixMyStreet/Cobrand/SeeSomething.pm
index e5e937267..af386429c 100644
--- a/perllib/FixMyStreet/Cobrand/SeeSomething.pm
+++ b/perllib/FixMyStreet/Cobrand/SeeSomething.pm
@@ -88,14 +88,15 @@ sub admin_stats {
my %councils =
map {
- $c->stash->{council_details}->{$_}->{name} =~ s/(?:Borough|City) Council//;
- $_ => $c->stash->{council_details}->{$_}
+ my $name = $_->name;
+ $name =~ s/(?:Borough|City) Council//;
+ ($_->id => $name);
}
- @{ $self->council_id };
+ $c->model('DB::Body')->search({ id => $self->council_id });
$c->stash->{council_details} = \%councils;
- if ( !$c->user_exists || !grep { $_ == $c->user->from_council } @{ $self->council_id } ) {
+ if ( !$c->user_exists || !grep { $_ == $c->user->from_body->id } @{ $self->council_id } ) {
$c->detach( '/page_error_404_not_found' );
}
@@ -123,7 +124,7 @@ sub admin_stats {
},
{
columns => [ qw(
- service category subcategory council confirmed
+ service category subcategory confirmed bodies_str
) ],
order_by => { -desc=> [ 'confirmed' ] },
rows => 20,
diff --git a/t/cobrand/seesomething.t b/t/cobrand/seesomething.t
new file mode 100644
index 000000000..3e818f2d1
--- /dev/null
+++ b/t/cobrand/seesomething.t
@@ -0,0 +1,39 @@
+use strict;
+use warnings;
+use DateTime;
+use Test::More;
+use JSON;
+
+use FixMyStreet;
+use FixMyStreet::TestMech;
+
+my $EMAIL = 'seesomething@example.com';
+
+my $mech = FixMyStreet::TestMech->new;
+my $user = $mech->create_user_ok( $EMAIL );
+
+my $body = $mech->create_body_ok( 2520, 'Coventry City Council' );
+$mech->create_body_ok( 2522, 'Dudley Borough Council' );
+$mech->create_body_ok( 2514, 'Birmingham City Council' );
+$mech->create_body_ok( 2546, 'Walsall Borough Council' );
+$mech->create_body_ok( 2519, 'Wolverhampton City Council' );
+$mech->create_body_ok( 2538, 'Solihull Borough Council' );
+$mech->create_body_ok( 2535, 'Sandwell Borough Council' );
+
+$user->update({ from_body => $body });
+
+subtest 'admin/stats' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'seesomething' ],
+ }, sub {
+ my $user = $mech->log_in_ok( $EMAIL );
+
+ $mech->get( '/admin/stats' );
+ ok $mech->success or do {
+ diag $mech->content;
+ diag $mech->status;
+ };
+ }
+};
+
+done_testing;
diff --git a/templates/web/seesomething/admin/stats.html b/templates/web/seesomething/admin/stats.html
index 713c3fb6d..b69973af4 100644
--- a/templates/web/seesomething/admin/stats.html
+++ b/templates/web/seesomething/admin/stats.html
@@ -50,7 +50,7 @@ No Results found
<td>[% report.service || 'Other' %]</td>
<td>[% report.category %]</td>
<td class="nowrap">[% report.subcategory %]</td>
- <td class="nowrap">[% council_details.${report.council}.name %]</td>
+ <td class="nowrap">[% council_details.${report.bodies_str}.name %]</td>
<td class="nowrap">[% PROCESS format_time time=report.confirmed %]</td>
</tr>
[%- END %]