21
1
Fork 0
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:
Colin Darie 2018-08-29 16:33:36 +02:00
parent abaa800c97
commit ef1229d900
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 16 additions and 0 deletions

View file

@ -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

View file

@ -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