diff options
-rw-r--r-- | perllib/FixMyStreet/App/Model/PhotoSet.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 2 | ||||
-rw-r--r-- | t/app/model/photoset.t | 4 |
3 files changed, 15 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm index f1334ff38..e8396b5aa 100644 --- a/perllib/FixMyStreet/App/Model/PhotoSet.pm +++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm @@ -14,25 +14,30 @@ has c => ( is => 'ro', ); +# The attached report, for using its ID has object => ( is => 'ro', ); -has data => ( # generic data from DB field +# If a PhotoSet is generated from a database row, db_data is set, which then +# fills data_items -> images -> data. If it is generated during creation, +# data_items is set, which then similarly fills images -> data. + +has db_data => ( # generic data from DB field + is => 'ro', +); + +has data => ( # List of photo hashes is => 'ro', lazy => 1, default => sub { - # yes, this is a little circular: data -> data_items -> items -> data - # e.g. if not provided, then we're presumably uploading/etc., so calculate from - # the stored cached fileids - # (obviously if you provide none of these, then you'll get an infinite loop) my $self = shift; my $data = join ',', map { $_->[0] } $self->all_images; return $data; } ); -has data_items => ( # either a) split from data or b) provided by photo upload +has data_items => ( # either a) split from db_data or b) provided by photo upload isa => 'ArrayRef', is => 'rw', traits => ['Array'], @@ -42,8 +47,7 @@ has data_items => ( # either a) split from data or b) provided by photo upload }, default => sub { my $self = shift; - my $data = $self->data - or return []; + my $data = $self->db_data or return []; return [$data] if (_jpeg_magic($data)); diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index f2df41f09..449bb5be8 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -869,7 +869,7 @@ sub get_photoset { eval "use $class"; return $class->new({ c => $c, - data => $self->photo, + db_data => $self->photo, object => $self, }); } diff --git a/t/app/model/photoset.t b/t/app/model/photoset.t index 938c77b2a..cfb5236a8 100644 --- a/t/app/model/photoset.t +++ b/t/app/model/photoset.t @@ -5,7 +5,6 @@ use Test::Exception; use utf8; use FixMyStreet::DB; -use Data::Dumper; use DateTime; use Path::Tiny 'path'; use File::Temp 'tempdir'; @@ -59,6 +58,7 @@ subtest 'Photoset with photo inline in DB' => sub { my $report = make_report( $image_path->slurp ); my $photoset = $report->get_photoset(); is $photoset->num_images, 1, 'Found just 1 image'; + is $photoset->data, '1cdd4329ceee2234bd4e89cb33b42061a0724687'; }; $image_path->copy( path( $UPLOAD_DIR, '0123456789012345678901234567890123456789.jpeg' ) ); @@ -68,7 +68,7 @@ subtest 'Photoset with 1 referenced photo' => sub { is $photoset->num_images, 1, 'Found just 1 image'; }; -subtest 'Photoset with 1 referenced photo' => sub { +subtest 'Photoset with 3 referenced photo' => sub { my $report = make_report( '0123456789012345678901234567890123456789,0123456789012345678901234567890123456789,0123456789012345678901234567890123456789' ); my $photoset = $report->get_photoset(); is $photoset->num_images, 3, 'Found 3 images'; |