diff options
Diffstat (limited to 't/app/model/photoset.t')
-rw-r--r-- | t/app/model/photoset.t | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/t/app/model/photoset.t b/t/app/model/photoset.t index 9e566f873..cfb5236a8 100644 --- a/t/app/model/photoset.t +++ b/t/app/model/photoset.t @@ -4,27 +4,29 @@ use Test::More; use Test::Exception; use utf8; -use FixMyStreet::App; -use Data::Dumper; +use FixMyStreet::DB; use DateTime; use Path::Tiny 'path'; use File::Temp 'tempdir'; my $dt = DateTime->now; -my $c = FixMyStreet::App->new; my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); -local $c->config->{UPLOAD_DIR} = $UPLOAD_DIR; -my $user = $c->model('DB::User')->find_or_create({ +my $db = FixMyStreet::DB->storage->schema; + +my $user = $db->resultset('User')->find_or_create({ name => 'Bob', email => 'bob@example.com', }); -my $image_path = path('t/app/controller/sample.jpg'); +FixMyStreet::override_config { + UPLOAD_DIR => $UPLOAD_DIR, +}, sub { -my $db = FixMyStreet::App->model('DB')->schema; $db->txn_begin; +my $image_path = path('t/app/controller/sample.jpg'); + sub make_report { my $photo_data = shift; return $db->resultset('Problem')->create({ @@ -54,23 +56,26 @@ sub make_report { subtest 'Photoset with photo inline in DB' => sub { my $report = make_report( $image_path->slurp ); - my $photoset = $report->get_photoset($c); + 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' ) ); subtest 'Photoset with 1 referenced photo' => sub { my $report = make_report( '0123456789012345678901234567890123456789' ); - my $photoset = $report->get_photoset($c); + my $photoset = $report->get_photoset(); 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($c); + my $photoset = $report->get_photoset(); is $photoset->num_images, 3, 'Found 3 images'; }; $db->txn_rollback; +}; + done_testing(); |