Fixed email notifications of recurrent failures

This commit is contained in:
Colin Darie 2018-09-01 10:48:50 +02:00
parent 7d5c7de7fe
commit 77c26264f0
No known key found for this signature in database
GPG Key ID: 4FB865FDBCA4BCC4
4 changed files with 21 additions and 1 deletions

View File

@ -22,7 +22,7 @@ module Notifier
.deliver_now
end
def ssl_notify_expires_soon(_notification)
def ssl_notify_expires_soon(check_notification)
NotificationsMailer.with(check_notification: check_notification)
.ssl_expires_soon
.deliver_now

View File

@ -13,6 +13,7 @@ module Notifier
def checks_recurrent_failures(min_consecutive)
Check
.active
.auto
.consecutive_failures(min_consecutive)
.includes(:user)
.where.not(user: ignore_users)

View File

@ -84,6 +84,15 @@ FactoryBot.define do
active false
end
trait :auto do
mode :auto
end
trait :manual do
mode :manual
domain "unupported.wxyz"
end
trait :with_notifications do
after :create do |check|
create_list :check_notification, 2,

View File

@ -91,6 +91,16 @@ module Notifier
assert_includes checks, c2
end
test "#checks_recurrent_failures ignores manual checks" do
c1 = create(:check, :last_runs_failed, :manual)
c2 = create(:check, :last_runs_failed, :auto)
checks = @resolver.checks_recurrent_failures(4)
assert_not_includes checks, c1
assert_includes checks, c2
end
test "#checks_recurrent_failures ignores user having notification disabled" do
c1 = create(:check, :last_runs_failed)
c1.user.update_attribute(:notifications_enabled, false)