aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-05-26 17:17:24 +0100
committerStruan Donald <struan@exo.org.uk>2011-05-26 17:17:24 +0100
commit860f2965f9af0699a40e022ba7c7370a304a4313 (patch)
tree3cf65ef4fedf85a343d3d290288b73d26b4585fa /t/app/controller
parentf7a711c5b544d876928ba572f46912e09eff9b83 (diff)
use moose role for is_from_abuser method
Diffstat (limited to 't/app/controller')
-rw-r--r--t/app/controller/alert_new.t79
1 files changed, 79 insertions, 0 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 4b23cb950..3d06594de 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -250,4 +250,83 @@ foreach my $test (
};
}
+for my $test (
+ {
+ email => 'test@example.com',
+ type => 'new_updates',
+ content => 'your alert will not be activated',
+ email_text => 'confirm the alert',
+ uri => '/alert/subscribe?type=updates&rznvy=test@example.com&id=1',
+ param1 => 1,
+ }
+ )
+{
+ subtest "cannot sign up for alert if in abuse table" => sub {
+ $mech->clear_emails_ok;
+
+ my $type = $test->{type};
+
+ my $user =
+ FixMyStreet::App->model('DB::User')
+ ->find( { email => $test->{email} } );
+
+ # we don't want an alert
+ my $alert;
+ if ($user) {
+ $mech->delete_user($user);
+ }
+
+ my $abuse =
+ FixMyStreet::App->model('DB::Abuse')
+ ->find_or_create( { email => $test->{email} } );
+
+ $mech->get_ok( $test->{uri} );
+ $mech->content_contains( $test->{content} );
+
+ $user =
+ FixMyStreet::App->model('DB::User')
+ ->find( { email => $test->{email} } );
+
+ ok $user, 'user created for alert';
+
+ $alert = FixMyStreet::App->model('DB::Alert')->find(
+ {
+ user => $user,
+ alert_type => $type,
+ parameter => $test->{param1},
+ parameter2 => $test->{param2},
+ confirmed => 0,
+ }
+ );
+
+ ok $alert, "Found the alert";
+
+ my $email = $mech->get_email;
+ ok $email, "got an email";
+ like $email->body, qr/$test->{email_text}/i, "Correct email text";
+
+ my ( $url, $url_token ) = $email->body =~ m{(http://\S+/A/)(\S+)};
+ ok $url, "extracted confirm url '$url'";
+
+ my $token = FixMyStreet::App->model('DB::Token')->find(
+ {
+ token => $url_token,
+ scope => 'alert'
+ }
+ );
+ ok $token, 'Token found in database';
+ ok $alert->id == $token->data->{id}, 'token alertid matches alert id';
+
+ $mech->clear_emails_ok;
+
+ $mech->get_ok("/A/$url_token");
+ $mech->content_contains('error confirming');
+
+ $alert->discard_changes;
+
+ ok !$alert->confirmed, 'alert not set to confirmed';
+
+ $abuse->delete;
+ };
+}
done_testing();