From 76e533bd318cb4208faa1bf5cd0c00bde9e08e6c Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 13 Mar 2015 18:04:55 +0000 Subject: Factor out test contact creation to function. --- perllib/FixMyStreet/TestMech.pm | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'perllib/FixMyStreet/TestMech.pm') diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index 72a6810bc..cd846dcd8 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -151,23 +151,21 @@ sub delete_user { ->find( { email => $email_or_user } ); # If no user found we can't delete them - if ( !$user ) { - ok( 1, "No user found to delete" ); - return 1; - } + return 1 unless $user; + + $mech->get('/auth/sign_out'); - $mech->log_out_ok; for my $p ( $user->problems ) { - ok( $_->delete, "delete comment " . $_->text ) for $p->comments; - ok( $_->delete, "delete questionnaire " . $_->id ) for $p->questionnaires; - ok( $p->delete, "delete problem " . $p->title ); + $p->comments->delete; + $p->questionnaires->delete; + $p->delete; } for my $a ( $user->alerts ) { $a->alerts_sent->delete; - ok( $a->delete, "delete alert " . $a->alert_type ); + $a->delete; } - ok( $_->delete, "delete comment " . $_->text ) for $user->comments; - ok $user->delete, "delete test user " . $user->email; + $_->delete for $user->comments; + $user->delete; return 1; } @@ -559,6 +557,21 @@ sub delete_problems_for_body { } } +sub create_contact_ok { + my $self = shift; + my %contact_params = ( + confirmed => 1, + deleted => 0, + editor => 'Test', + whenedited => \'current_timestamp', + note => 'Created for test', + @_ + ); + my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( \%contact_params ); + ok $contact, 'found/created contact ' . $contact->category;; + return $contact; +} + sub create_body_ok { my $self = shift; my ( $area_id, $name, %extra ) = @_; -- cgit v1.2.3