aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm11
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm2
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Body.pm8
-rw-r--r--t/app/controller/report_display.t13
-rw-r--r--t/app/controller/reports.t23
-rw-r--r--templates/web/base/admin/body.html2
7 files changed, 50 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b0892c176..fccdbfcca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@
- Fix subcategory issues when visiting /report/new directly #2276
- Development improvements:
- Add cobrand hook for dashboard viewing permission. #2285
+ - Have body.url work in hashref lookup. #2284
- Internal things:
- Move send-comments code to package for testing. #2109 #2170
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index 74a38f225..d459d5f02 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -138,10 +138,17 @@ use namespace::clean;
with 'FixMyStreet::Roles::Translatable',
'FixMyStreet::Roles::Extra';
+sub _url {
+ my ( $obj, $cobrand, $args ) = @_;
+ my $uri = URI->new('/reports/' . $cobrand->short_name($obj));
+ $uri->query_form($args) if $args;
+ return $uri;
+}
+
sub url {
my ( $self, $c, $args ) = @_;
- # XXX $areas_info was used here for Norway parent - needs body parents, I guess
- return $c->uri_for( '/reports/' . $c->cobrand->short_name( $self ), $args || {} );
+ my $cobrand = $self->result_source->schema->cobrand;
+ return _url($self, $cobrand, $args);
}
__PACKAGE__->might_have(
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 2192158d3..a222c78cd 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -663,7 +663,7 @@ sub body {
my @body_names = sort map {
my $name = $_->name;
if ($c and FixMyStreet->config('AREA_LINKS_FROM_PROBLEMS')) {
- '<a href="' . $_->url($c) . '">' . $name . '</a>';
+ '<a href="' . $_->url . '">' . $name . '</a>';
} else {
$name;
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/Body.pm b/perllib/FixMyStreet/DB/ResultSet/Body.pm
index 1855a45c1..4e9661d2e 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Body.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Body.pm
@@ -149,9 +149,17 @@ sub all_sorted {
})->all;
@bodies = sort { strcoll($a->{msgstr} || $a->{name}, $b->{msgstr} || $b->{name}) } @bodies;
+ my $cobrand = $rs->result_source->schema->cobrand;
+
foreach my $body (@bodies) {
$body->{parent} = { id => $body->{parent}, name => $body->{parent_name} } if $body->{parent};
+ # DEPRECATED: url(c, query_params) -> url
+ $body->{url} = sub {
+ my ($c, $args) = @_;
+ return FixMyStreet::DB::Result::Body::_url($body, $cobrand, $args);
+ };
+
# DEPRECATED: get_column('area_count') -> area_count
next unless defined $body->{area_count};
$body->{get_column} = sub {
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index 17b9180c1..a20eec005 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -129,6 +129,7 @@ subtest "test a good report" => sub {
'Reported by Test User at 15:47, Sat 16 April 2011',
'correct problem meta information';
$mech->content_contains('Test 2 Detail');
+ $mech->content_lacks('Sent to');
my $update_form = $mech->form_name('updateForm');
@@ -142,6 +143,18 @@ subtest "test a good report" => sub {
is $update_form->value($_), $fields{$_}, "$_ value" for keys %fields;
};
+subtest "test duration string" => sub {
+ $report->update({ whensent => \'current_timestamp' });
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains('Sent to Westminster');
+ FixMyStreet::override_config {
+ AREA_LINKS_FROM_PROBLEMS => 1,
+ }, sub {
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains('Sent to <a href="/reports/Westminster+City+Council">Westminster');
+ };
+};
+
foreach my $meta (
{
anonymous => 'f',
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index c57b15a8e..66af2778d 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -1,7 +1,7 @@
use Test::MockTime qw(:all);
use FixMyStreet::TestMech;
use mySociety::MaPit;
-use FixMyStreet::App;
+use FixMyStreet::DB;
use FixMyStreet::Script::UpdateAllReports;
use DateTime;
@@ -95,8 +95,19 @@ $fife_problems[10]->update( {
state => 'hidden',
});
-# Run the cron script old-data (for the table no longer used by default)
-FixMyStreet::Script::UpdateAllReports::generate(1);
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+}, sub {
+ subtest 'Test the cron script old-data (for the table no longer used by default)' => sub {
+ FixMyStreet::Script::UpdateAllReports::generate(1);
+
+ # Old style page no longer exists in core, but let's just check the code works okay
+ my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('fixmystreet')->new();
+ FixMyStreet::DB->schema->cobrand($cobrand);
+ my @bodies = FixMyStreet::DB->resultset('Body')->active->translated->all_sorted;
+ is $bodies[0]->{url}->(), '/reports/Birmingham';
+ };
+};
# Run the cron script that makes the data for /reports so we don't get an error.
my $data = FixMyStreet::Script::UpdateAllReports::generate_dashboard();
@@ -254,7 +265,7 @@ subtest "it lists shortlisted reports" => sub {
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/'
}, sub {
- my $body = FixMyStreet::App->model('DB::Body')->find( $body_edin_id );
+ my $body = FixMyStreet::DB->resultset('Body')->find( $body_edin_id );
my $user = $mech->log_in_ok( 'test@example.com' );
$user->update({ from_body => $body });
$user->user_body_permissions->find_or_create({
@@ -304,7 +315,7 @@ subtest "it allows body users to filter by subtypes" => sub {
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/'
}, sub {
- my $body = FixMyStreet::App->model('DB::Body')->find( $body_edin_id );
+ my $body = FixMyStreet::DB->resultset('Body')->find( $body_edin_id );
my $user = $mech->log_in_ok( 'test@example.com' );
$user->update({ from_body => $body });
@@ -363,7 +374,7 @@ subtest "it does not allow body users to filter subcategories for other bodies"
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/'
}, sub {
- my $body = FixMyStreet::App->model('DB::Body')->find( $body_west_id );
+ my $body = FixMyStreet::DB->resultset('Body')->find( $body_west_id );
my $user = $mech->log_in_ok( 'test@example.com' );
$user->update({ from_body => $body });
diff --git a/templates/web/base/admin/body.html b/templates/web/base/admin/body.html
index 2d77f10ce..37ab24496 100644
--- a/templates/web/base/admin/body.html
+++ b/templates/web/base/admin/body.html
@@ -28,7 +28,7 @@
[% END %]
[% END %]
<br>
- <a href="[% c.uri_for_email(body.url(c)) %]" class="admin-offsite-link">[% loc('List all reported problems' ) %]</a> |
+ <a href="[% c.uri_for_email(body.url) %]" class="admin-offsite-link">[% loc('List all reported problems' ) %]</a> |
<a href="[% c.uri_for( 'body', body_id, { text => 1 } ) %]">[% loc('Text only version') %]</a>
</p>