Reset consecutive failures after changing domain or mode

This commit is contained in:
Colin Darie 2018-08-31 14:27:00 +02:00
parent 95b437bf3d
commit ccde868457
No known key found for this signature in database
GPG Key ID: 4FB865FDBCA4BCC4
2 changed files with 22 additions and 1 deletions

View File

@ -128,7 +128,7 @@ class Check < ApplicationRecord
end
def reset_consecutive_failures
return unless last_success_at_changed?
return unless last_success_at_changed? || mode_changed? || domain_changed?
return if consecutive_failures_changed?
self.consecutive_failures = 0

View File

@ -55,6 +55,27 @@ class CheckTest < ActiveSupport::TestCase
assert_nil check_notification.sent_at
end
test "consecutive failures are resetted when domain changed" do
check = create(:check, consecutive_failures: 1)
check.domain = "mynewdomain.fr"
check.save!
assert_equal 0, check.consecutive_failures
end
test "consecutive failures are resetted when mode changed" do
check = create(:check, consecutive_failures: 1, mode: :auto)
check.manual!
assert_equal 0, check.consecutive_failures
check = create(:check, domain: "x.wxyz", consecutive_failures: 1, mode: :manual)
check.auto!
assert_equal 0, check.consecutive_failures
end
test "days_from_last_success without any success" do
check = build(:check)
assert_nil check.days_from_last_success