diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-07-18 17:20:04 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-07-18 17:21:45 +0100 |
commit | 60adb1e8635996a1b4ef96bcf3ef99ca01505b46 (patch) | |
tree | 35280a7863bf615887f92465278fe96d8a0789e7 | |
parent | 755f0c7ee75fe3092671e9d1f7f46603ccc3bfc5 (diff) |
Fix update-all-reports when database empty.
-rwxr-xr-x | perllib/FixMyStreet/Script/UpdateAllReports.pm | 7 | ||||
-rw-r--r-- | t/app/controller/reports.t | 5 |
2 files changed, 10 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/Script/UpdateAllReports.pm b/perllib/FixMyStreet/Script/UpdateAllReports.pm index 5751e05ac..51cb7b856 100755 --- a/perllib/FixMyStreet/Script/UpdateAllReports.pm +++ b/perllib/FixMyStreet/Script/UpdateAllReports.pm @@ -115,7 +115,12 @@ sub generate_dashboard { }, { select => [ { min => 'confirmed' } ], as => [ 'confirmed' ], - })->first->confirmed->truncate(to => 'day'); + })->first->confirmed; + if ($min_confirmed) { + $min_confirmed = $min_confirmed->truncate(to => 'day'); + } else { + $min_confirmed = FixMyStreet->set_time_zone(DateTime->now)->truncate(to => 'day'); + } my ($group_by, $extra); if (DateTime::Duration->compare($end_today - $min_confirmed, DateTime::Duration->new(months => 1)) < 0) { diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 15e7e3718..dd84d3d2e 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -2,6 +2,7 @@ use Test::MockTime qw(:all); use FixMyStreet::TestMech; use mySociety::MaPit; use FixMyStreet::App; +use FixMyStreet::Script::UpdateAllReports; use DateTime; set_absolute_time('2017-07-07T16:00:00'); @@ -11,6 +12,9 @@ END { ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' ); +# Run the cron script with empty database +FixMyStreet::Script::UpdateAllReports::generate_dashboard(); + $mech->create_body_ok(2514, 'Birmingham City Council'); my $body_edin_id = $mech->create_body_ok(2651, 'City of Edinburgh Council')->id; my $body_west_id = $mech->create_body_ok(2504, 'Westminster City Council')->id; @@ -85,7 +89,6 @@ $fife_problems[10]->update( { }); # Run the cron script that makes the data for /reports so we don't get an error. -use FixMyStreet::Script::UpdateAllReports; FixMyStreet::Script::UpdateAllReports::generate_dashboard(); # check that we can get the page |