aboutsummaryrefslogtreecommitdiffstats
path: root/t/app
diff options
context:
space:
mode:
authorpezholio <pezholio@gmail.com>2017-01-17 16:44:50 +0000
committerDave Arter <davea@mysociety.org>2017-02-15 13:28:04 +0000
commitb14319e75b61ce1ee21ebb7d6fa924ebe18ceee9 (patch)
treea127709b1254de587fadce5f3b7aa82decffc09a /t/app
parent0b1ab9fb1145ca32dced46b4faefe49da5c76768 (diff)
Add Problem->time_ago for pretty-printed duration
Diffstat (limited to 't/app')
-rw-r--r--t/app/model/problem.t44
1 files changed, 44 insertions, 0 deletions
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 1130078c0..e2c407ffb 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -774,6 +774,50 @@ subtest 'check duplicate reports' => sub {
is $problem2->duplicates->[0]->title, $problem1->title, 'problem2 includes problem1 in duplicates';
};
+subtest 'get report time ago in appropriate format' => sub {
+ my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE');
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( minutes => 2)
+ } );
+ is $problem->time_ago, '2 minutes', 'problem returns time ago in minutes';
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( hours => 18)
+ } );
+ is $problem->time_ago, '18 hours', 'problem returns time ago in hours';
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( days => 4)
+ } );
+ is $problem->time_ago, '4 days', 'problem returns time ago in days';
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( weeks => 3 )
+ } );
+ is $problem->time_ago, '3 weeks', 'problem returns time ago in weeks';
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( months => 4 )
+ } );
+ is $problem->time_ago, '4 months', 'problem returns time ago in months';
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( years => 2 )
+ } );
+ is $problem->time_ago, '2 years', 'problem returns time ago in years';
+
+};
+
+subtest 'time ago works with other dates' => sub {
+ my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE');
+
+ $problem->update( {
+ lastupdate => DateTime->now->subtract( days => 4)
+ } );
+ is $problem->time_ago('lastupdate'), '4 days', 'problem returns last updated time ago in days';
+};
+
END {
$problem->comments->delete if $problem;
$problem->delete if $problem;