mirror of
https://github.com/Evolix/chexpire.git
synced 2024-04-28 15:00:50 +02:00
Add Check.domain_expires_in_days
This commit is contained in:
parent
54e57f20ae
commit
e9de5d5c32
|
@ -11,19 +11,15 @@ class NotificationsMailer < ApplicationMailer
|
|||
end
|
||||
|
||||
def domain_expires_soon
|
||||
@expire_in_days = Integer(@check.domain_expires_at.to_date - Date.today)
|
||||
|
||||
I18n.with_locale params&.fetch(:locale) { @check.user.locale } do
|
||||
subject = t(".subject", domain: @check.domain, count: @expire_in_days)
|
||||
subject = t(".subject", domain: @check.domain, count: @check.domain_expires_in_days)
|
||||
mail subject: subject, to: @notification.recipient
|
||||
end
|
||||
end
|
||||
|
||||
def ssl_expires_soon
|
||||
@expire_in_days = Integer(@check.domain_expires_at.to_date - Date.today)
|
||||
|
||||
I18n.with_locale params&.fetch(:locale) { @check.user.locale } do
|
||||
subject = t(".subject", domain: @check.domain, count: @expire_in_days)
|
||||
subject = t(".subject", domain: @check.domain, count: @check.domain_expires_in_days)
|
||||
mail subject: subject, to: @notification.recipient
|
||||
end
|
||||
end
|
||||
|
|
|
@ -105,6 +105,10 @@ class Check < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def domain_expires_in_days
|
||||
Integer(domain_expires_at.to_date - Time.now.utc.to_date)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def domain_created_at_past
|
||||
|
|
|
@ -123,4 +123,16 @@ class CheckTest < ActiveSupport::TestCase
|
|||
check.save!
|
||||
assert check.mode?
|
||||
end
|
||||
|
||||
test "expiration in days (future)" do
|
||||
check = create(:check, domain_expires_at: 1.week.from_now)
|
||||
|
||||
assert_equal 7, check.domain_expires_in_days
|
||||
end
|
||||
|
||||
test "expiration in days (past)" do
|
||||
check = create(:check, domain_expires_at: 1.week.ago)
|
||||
|
||||
assert_equal -7, check.domain_expires_in_days
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue