Commit 4d4016e5c3295a1a64991b46fefcc0941c407079
1 parent
742c74a4
Exists in
master
and in
28 other branches
person-notifier-test: avoid more randomness
Showing
1 changed file
with
13 additions
and
4 deletions
Show diff stats
test/unit/person_notifier_test.rb
| ... | ... | @@ -25,6 +25,7 @@ class PersonNotifierTest < ActiveSupport::TestCase |
| 25 | 25 | |
| 26 | 26 | should 'deliver mail to community members' do |
| 27 | 27 | @community.add_member(@member) |
| 28 | + process_delayed_job_queue | |
| 28 | 29 | notify |
| 29 | 30 | sent = ActionMailer::Base.deliveries.first |
| 30 | 31 | assert_equal [@member.email], sent.to |
| ... | ... | @@ -48,8 +49,9 @@ class PersonNotifierTest < ActiveSupport::TestCase |
| 48 | 49 | should 'display author name in delivered mail' do |
| 49 | 50 | @community.add_member(@member) |
| 50 | 51 | Comment.create!(:author => @admin, :title => 'test comment', :body => 'body!', :source => @article) |
| 52 | + process_delayed_job_queue | |
| 51 | 53 | notify |
| 52 | - sent = ActionMailer::Base.deliveries.first | |
| 54 | + sent = ActionMailer::Base.deliveries.last | |
| 53 | 55 | assert_match /#{@admin.name}/, sent.body |
| 54 | 56 | end |
| 55 | 57 | |
| ... | ... | @@ -81,8 +83,11 @@ class PersonNotifierTest < ActiveSupport::TestCase |
| 81 | 83 | |
| 82 | 84 | should 'schedule next mail at notification time' do |
| 83 | 85 | @member.notification_time = 12 |
| 86 | + time = Time.now | |
| 84 | 87 | @member.notifier.schedule_next_notification_mail |
| 85 | - assert_equal @member.notification_time, DateTime.now.hour - Delayed::Job.first.run_at.hour | |
| 88 | + job = Delayed::Job.where("handler like '%PersonNotifier::NotifyJob%'").last | |
| 89 | + assert job.run_at >= time + @member.notification_time.hours | |
| 90 | + assert job.run_at < time + (@member.notification_time+1).hours | |
| 86 | 91 | end |
| 87 | 92 | |
| 88 | 93 | should 'do not schedule duplicated notification mail' do |
| ... | ... | @@ -130,6 +135,7 @@ class PersonNotifierTest < ActiveSupport::TestCase |
| 130 | 135 | end |
| 131 | 136 | |
| 132 | 137 | should 'reschedule with changed notification time' do |
| 138 | + time = Time.now | |
| 133 | 139 | assert_difference Delayed::Job, :count, 1 do |
| 134 | 140 | @member.notification_time = 2 |
| 135 | 141 | @member.save! |
| ... | ... | @@ -138,13 +144,17 @@ class PersonNotifierTest < ActiveSupport::TestCase |
| 138 | 144 | @member.notification_time = 12 |
| 139 | 145 | @member.save! |
| 140 | 146 | end |
| 141 | - assert_equal @member.notification_time, DateTime.now.hour - Delayed::Job.first.run_at.hour | |
| 147 | + @member.notifier.schedule_next_notification_mail | |
| 148 | + job = Delayed::Job.where("handler like '%PersonNotifier::NotifyJob%'").last | |
| 149 | + assert job.run_at >= time + @member.notification_time.hours | |
| 150 | + assert job.run_at < time + (@member.notification_time+1).hours | |
| 142 | 151 | end |
| 143 | 152 | |
| 144 | 153 | should 'display error message if fail to render a notificiation' do |
| 145 | 154 | @community.add_member(@member) |
| 146 | 155 | Comment.create!(:author => @admin, :title => 'test comment', :body => 'body!', :source => @article) |
| 147 | 156 | ActionTracker::Record.any_instance.stubs(:verb).returns("some_invalid_verb") |
| 157 | + process_delayed_job_queue | |
| 148 | 158 | notify |
| 149 | 159 | sent = ActionMailer::Base.deliveries.last |
| 150 | 160 | assert_match /cannot render notification for some_invalid_verb/, sent.body |
| ... | ... | @@ -217,7 +227,6 @@ class PersonNotifierTest < ActiveSupport::TestCase |
| 217 | 227 | end |
| 218 | 228 | |
| 219 | 229 | def notify |
| 220 | - process_delayed_job_queue | |
| 221 | 230 | @member.notifier.notify |
| 222 | 231 | end |
| 223 | 232 | ... | ... |