aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-05-27 16:40:36 +0100
committerStruan Donald <struan@exo.org.uk>2011-05-27 16:43:42 +0100
commita888f0e31747bd6e1b3733d70569d151607fde22 (patch)
treea88999ecf1d715706143ad27cd75810c12c374e7
parent778f6498b17f51aa30a948ede177f0c681c0f228 (diff)
check for uninflated/null dates before trying to set the timezoned
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm12
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm24
-rw-r--r--t/app/model/comment.t27
-rw-r--r--t/app/model/problem.t34
4 files changed, 89 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index f51c939ff..40801306b 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -80,7 +80,11 @@ with 'FixMyStreet::Roles::Abuser';
my $tz = DateTime::TimeZone->new( name => "local" );
sub created_local {
- return shift->created->set_time_zone($tz);
+ my $self = shift;
+
+ return $self->created
+ ? $self->created->set_time_zone($tz)
+ : $self->created;
}
sub confirmed_local {
@@ -88,9 +92,9 @@ sub confirmed_local {
# if confirmed is null then it doesn't get inflated so don't
# try and set the timezone
- return $self->confirmed->set_time_zone($tz) if $self->confirmed;
-
- return 0;
+ return $self->confirmed
+ ? $self->confirmed->set_time_zone($tz)
+ : $self->confirmed;
}
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 2836f6c92..426f791c7 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -112,19 +112,35 @@ with 'FixMyStreet::Roles::Abuser';
my $tz = DateTime::TimeZone->new( name => "local" );
sub confirmed_local {
- return shift->confirmed->set_time_zone($tz);
+ my $self = shift;
+
+ return $self->confirmed
+ ? $self->confirmed->set_time_zone($tz)
+ : $self->confirmed;
}
sub created_local {
- return shift->created->set_time_zone($tz);
+ my $self = shift;
+
+ return $self->created
+ ? $self->created->set_time_zone($tz)
+ : $self->created;
}
sub whensent_local {
- return shift->whensent->set_time_zone($tz);
+ my $self = shift;
+
+ return $self->whensent
+ ? $self->whensent->set_time_zone($tz)
+ : $self->confirmed;
}
sub lastupdate_local {
- return shift->lastupdate->set_time_zone($tz);
+ my $self = shift;
+
+ return $self->lastupdate
+ ? $self->lastupdate->set_time_zone($tz)
+ : $self->lastupdate;
}
=head2 check_for_errors
diff --git a/t/app/model/comment.t b/t/app/model/comment.t
new file mode 100644
index 000000000..93104c2e5
--- /dev/null
+++ b/t/app/model/comment.t
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+use FixMyStreet;
+use FixMyStreet::App;
+
+my $comment_rs = FixMyStreet::App->model('DB::Comment');
+
+my $comment = $comment_rs->new(
+ {
+ user_id => 1,
+ problem_id => 1,
+ text => '',
+ state => 'confirmed',
+ anonymous => 0,
+ mark_fixed => 0,
+ cobrand => 'default',
+ cobrand_data => '',
+ }
+);
+
+is $comment->confirmed_local, undef, 'inflating null confirmed ok';
+is $comment->created_local, undef, 'inflating null confirmed ok';
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
new file mode 100644
index 000000000..74dd877ae
--- /dev/null
+++ b/t/app/model/problem.t
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+
+use FixMyStreet;
+use FixMyStreet::App;
+
+my $problem_rs = FixMyStreet::App->model('DB::Problem');
+
+my $problem = $problem_rs->new(
+ {
+ postcode => 'EH99 1SP',
+ latitude => 1,
+ longitude => 1,
+ areas => 1,
+ title => '',
+ detail => '',
+ used_map => 1,
+ user_id => 1,
+ name => '',
+ state => 'confirmed',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ }
+);
+
+is $problem->confirmed_local, undef, 'inflating null confirmed ok';
+is $problem->whensent_local, undef, 'inflating null confirmed ok';
+is $problem->lastupdate_local, undef, 'inflating null confirmed ok';
+is $problem->created_local, undef, 'inflating null confirmed ok';