mirror of
https://github.com/Evolix/chexpire.git
synced 2024-04-26 05:50:50 +02:00
Check: set mode manual/auto before saving
This commit is contained in:
parent
abaa800c97
commit
ef1229d900
|
@ -55,6 +55,7 @@ class Check < ApplicationRecord
|
|||
validates :vendor, length: { maximum: 255 }
|
||||
|
||||
before_save :reset_consecutive_failures
|
||||
before_save :set_mode
|
||||
after_update :reset_notifications
|
||||
after_save :enqueue_sync
|
||||
|
||||
|
@ -128,4 +129,9 @@ class Check < ApplicationRecord
|
|||
|
||||
self.consecutive_failures = 0
|
||||
end
|
||||
|
||||
def set_mode
|
||||
return unless domain_changed?
|
||||
self.mode = supported? ? :auto : :manual
|
||||
end
|
||||
end
|
||||
|
|
|
@ -91,4 +91,14 @@ class CheckTest < ActiveSupport::TestCase
|
|||
check = build(:check, :ssl, domain: "domain.cn")
|
||||
assert check.supported?
|
||||
end
|
||||
|
||||
test "set mode before saving" do
|
||||
check = build(:check, domain: "domain.fr")
|
||||
check.save!
|
||||
assert check.auto?
|
||||
|
||||
check.domain = "domain.xyz"
|
||||
check.save!
|
||||
assert check.mode?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue