[Rt-commit] rt branch, 4.0/dashboard-subscriptions, created. rt-4.0.2-27-gb5e07b6

Jason May jasonmay at bestpractical.com
Thu Aug 25 16:51:54 EDT 2011


The branch, 4.0/dashboard-subscriptions has been created
        at  b5e07b6ca10b7a5926769dadc536e4e234878fee (commit)

- Log -----------------------------------------------------------------
commit cb9ffd37cbb59067f2f1b13dd0a8ecc74fbe64d0
Author: Jason May <jasonmay at bestpractical.com>
Date:   Tue Aug 23 12:53:26 2011 -0400

    Use the correct variable when checking subscription frequencies

diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
index f6b1685..026ae7c 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -161,7 +161,7 @@ sub IsSubscriptionReady {
 
     if ($sub_frequency eq 'weekly') {
         # correct day of week?
-        return 0 if $sub_frequency ne $dow;
+        return 0 if $sub_dow ne $dow;
 
         # does it match the "every N weeks" clause?
         $sub_fow = 1 if !$sub_fow;

commit 5eeb8ac23511dafb9bd9293ce3984fe642e7d4cf
Author: Jason May <jasonmay at bestpractical.com>
Date:   Thu Aug 25 16:46:02 2011 -0400

    Refactor various dashboard routines into subs for future reuse

diff --git a/t/mail/dashboards.t b/t/mail/dashboards.t
index 31fe701..80abc07 100644
--- a/t/mail/dashboards.t
+++ b/t/mail/dashboards.t
@@ -9,29 +9,63 @@ use RT::Dashboard::Mailer;
 my ($baseurl, $m) = RT::Test->started_ok;
 ok($m->login, 'logged in');
 
+sub create_dashboard {
+    my ($baseurl, $m) = @_;
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+    $m->get_ok($baseurl . '/Dashboards/Modify.html?Create=1');
+    $m->form_name('ModifyDashboard');
+    $m->field('Name' => 'Testing!');
+    $m->click_button(value => 'Create');
+    $m->title_is('Modify the dashboard Testing!');
+
+    $m->follow_link_ok({text => 'Content'});
+    $m->title_is('Modify the content of dashboard Testing!');
+
+    my $form = $m->form_name('Dashboard-Searches-body');
+    my @input = $form->find_input('Searches-body-Available');
+    my ($dashboards_component) =
+    map { ( $_->possible_values )[1] }
+    grep { ( $_->value_names )[1] =~ /Dashboards/ } @input;
+    $form->value('Searches-body-Available' => $dashboards_component );
+    $m->click_button(name => 'add');
+    $m->content_contains('Dashboard updated');
+
+    $m->follow_link_ok({text => 'Show'});
+    $m->title_is('Dashboard Testing!');
+    $m->content_contains('My dashboards');
+    $m->content_like(qr{<a href="/Dashboards/\d+/Testing!">Testing!</a>});
+
+}
+
+sub create_subscription {
+    my ($baseurl, $m, %fields) = @_;
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+    # create a subscription
+    $m->follow_link_ok({text => 'Subscription'});
+    $m->title_is('Subscribe to dashboard Testing!');
+    $m->form_name('SubscribeDashboard');
+    $m->set_fields(%fields);
+    $m->click_button(name => 'Save');
+    $m->content_contains("Subscribed to dashboard Testing!");
+}
+
+sub get_dash_sub_ids {
+    my $user = RT::User->new(RT->SystemUser);
+    $user->Load('root');
+    ok($user->Id, 'loaded user');
+    my ($subscription) = $user->Attributes->Named('Subscription');
+    my $subscription_id = $subscription->Id;
+    ok($subscription_id, 'loaded subscription');
+    my $dashboard_id = $subscription->SubValue('DashboardId');
+    ok($dashboard_id, 'got dashboard id');
+
+
+    return ($dashboard_id, $subscription_id);
+}
+
 # first, create and populate a dashboard
-$m->get_ok('/Dashboards/Modify.html?Create=1');
-$m->form_name('ModifyDashboard');
-$m->field('Name' => 'Testing!');
-$m->click_button(value => 'Create');
-$m->title_is('Modify the dashboard Testing!');
-
-$m->follow_link_ok({text => 'Content'});
-$m->title_is('Modify the content of dashboard Testing!');
-
-my $form = $m->form_name('Dashboard-Searches-body');
-my @input = $form->find_input('Searches-body-Available');
-my ($dashboards_component) =
-  map { ( $_->possible_values )[1] }
-  grep { ( $_->value_names )[1] =~ /Dashboards/ } @input;
-$form->value('Searches-body-Available' => $dashboards_component );
-$m->click_button(name => 'add');
-$m->content_contains('Dashboard updated');
-
-$m->follow_link_ok({text => 'Show'});
-$m->title_is('Dashboard Testing!');
-$m->content_contains('My dashboards');
-$m->content_like(qr{<a href="/Dashboards/\d+/Testing!">Testing!</a>});
+create_dashboard($baseurl, $m);
 
 # now test the mailer
 
@@ -48,26 +82,16 @@ RT::Dashboard::Mailer->MailDashboards(
 @mails = RT::Test->fetch_caught_mails;
 is @mails, 0, "no mail yet since there's no subscription";
 
-# create a subscription
-$m->follow_link_ok({text => 'Subscription'});
-$m->title_is('Subscribe to dashboard Testing!');
-$m->form_name('SubscribeDashboard');
-$m->field('Frequency' => 'daily');
-$m->field('Hour' => '06:00');
-$m->click_button(name => 'Save');
-$m->content_contains("Subscribed to dashboard Testing!");
-
-my $user = RT::User->new(RT->SystemUser);
-$user->Load('root');
-ok($user->Id, 'loaded user');
-my ($subscription) = $user->Attributes->Named('Subscription');
-my $subscription_id = $subscription->Id;
-ok($subscription_id, 'loaded subscription');
-my $dashboard_id = $subscription->SubValue('DashboardId');
-ok($dashboard_id, 'got dashboard id');
+create_subscription($baseurl, $m,
+    Frequency => 'daily',
+    Hour      => '06:00',
+);
+
+my ($dashboard_id, $subscription_id) = get_dash_sub_ids();
 
 sub produces_dashboard_mail_ok { # {{{
     my %args = @_;
+    my $subject = delete $args{Subject};
 
     local $Test::Builder::Level = $Test::Builder::Level + 1;
 
@@ -77,7 +101,7 @@ sub produces_dashboard_mail_ok { # {{{
     is @mails, 1, "got a dashboard mail";
 
     my $mail = parse_mail( $mails[0] );
-    is($mail->head->get('Subject'), "[example.com] Daily Dashboard: Testing!\n");
+    is($mail->head->get('Subject'), $subject);
     is($mail->head->get('From'), "root\n");
     is($mail->head->get('X-RT-Dashboard-Id'), "$dashboard_id\n");
     is($mail->head->get('X-RT-Dashboard-Subscription-Id'), "$subscription_id\n");
@@ -105,22 +129,28 @@ sub produces_no_dashboard_mail_ok { # {{{
 my $good_time = 1290337260; # 6:01 EST on a monday
 my $bad_time  = 1290340860; # 7:01 EST on a monday
 
+my $expected_subject = "[example.com] Daily Dashboard: Testing!\n";
+
 produces_dashboard_mail_ok(
     Time => $good_time,
+    Subject => $expected_subject,
 );
 
 produces_dashboard_mail_ok(
     All => 1,
+    Subject => $expected_subject,
 );
 
 produces_dashboard_mail_ok(
     All  => 1,
     Time => $good_time,
+    Subject => $expected_subject,
 );
 
 produces_dashboard_mail_ok(
     All  => 1,
     Time => $bad_time,
+    Subject => $expected_subject,
 );
 
 

commit b5e07b6ca10b7a5926769dadc536e4e234878fee
Author: Jason May <jasonmay at bestpractical.com>
Date:   Thu Aug 25 16:50:57 2011 -0400

    Add tests for weekly subscriptions
    
    The epoch timestamps were on a Sunday, not a Monday, so they were fixed
    as well.

diff --git a/t/mail/dashboards.t b/t/mail/dashboards.t
index 80abc07..8b7895c 100644
--- a/t/mail/dashboards.t
+++ b/t/mail/dashboards.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 72;
+use RT::Test tests => 96;
 use Test::Warn;
 use RT::Dashboard::Mailer;
 
@@ -126,8 +126,8 @@ sub produces_no_dashboard_mail_ok { # {{{
     is @mails, 0, $name;
 } # }}}
 
-my $good_time = 1290337260; # 6:01 EST on a monday
-my $bad_time  = 1290340860; # 7:01 EST on a monday
+my $good_time = 1290423660; # 6:01 EST on a monday
+my $bad_time  = 1290427260; # 7:01 EST on a monday
 
 my $expected_subject = "[example.com] Daily Dashboard: Testing!\n";
 
@@ -222,3 +222,32 @@ is($mail->head->get('X-RT-Dashboard-Subscription-Id'), "$subscription_id\n");
 RT::Dashboard::Mailer->MailDashboards(All => 1);
 @mails = RT::Test->fetch_caught_mails;
 is(@mails, 0, "no mail because the subscription notice happens only once");
+
+RT::Test->stop_server;
+RT::Test->clean_caught_mails;
+RT->Config->Set('EmailDashboardRemove' => ());
+RT->Config->Set('DashboardAddress' => 'root');
+($baseurl, $m) = RT::Test->started_ok;
+$m->login;
+create_dashboard($baseurl, $m);
+create_subscription($baseurl, $m,
+    Frequency => 'weekly',
+    Hour => '06:00',
+);
+
+($dashboard_id, $subscription_id) = get_dash_sub_ids();
+
+# bump $bad_time to Tuesday
+$bad_time = $good_time + 86400;
+
+produces_dashboard_mail_ok(
+    Time    => $good_time,
+    Subject =>  "[example.com] a Weekly b Testing! c\n",
+);
+
+produces_no_dashboard_mail_ok(
+    Name    => "no mail because it's the wrong time",
+    Time    => $bad_time,
+);
+
+RT::Test->clean_caught_mails;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list