Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications by email fixes #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/services/notifier/channels/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def domain_notify_expires_soon(check_notification)
.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
Expand Down
1 change: 1 addition & 0 deletions app/services/notifier/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def notifications_expiring_soon
def checks_recurrent_failures(min_consecutive)
Check
.active
.auto
.consecutive_failures(min_consecutive)
.includes(:user)
.where.not(user: ignore_users)
Expand Down
9 changes: 9 additions & 0 deletions test/factories/checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@
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,
Expand Down
8 changes: 6 additions & 2 deletions test/mailers/previews/notifications_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ class NotificationsMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/notifications_mailer/domain_expires_soon
def domain_expires_soon
check = Check.domain.first
NotificationsMailer.with(notification: check.notifications.first).domain_expires_soon
NotificationsMailer
.with(check_notification: check.check_notifications.first)
.domain_expires_soon
end

# Preview this email at http://localhost:3000/rails/mailers/notifications_mailer/ssl_expires_soon
def ssl_expires_soon
check = Check.ssl.first
NotificationsMailer.with(notification: check.notifications.first).ssl_expires_soon
NotificationsMailer
.with(check_notification: check.check_notifications.first)
.ssl_expires_soon
end

# Preview this email at http://localhost:3000/rails/mailers/notifications_mailer/recurrent_failures
Expand Down
10 changes: 10 additions & 0 deletions test/services/notifier/resolver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ class ResolverTest < ActiveSupport::TestCase
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)
Expand Down