Add Check.domain_expires_in_days

This commit is contained in:
Jérémy Lecour 2019-08-20 01:10:54 +02:00
parent 54e57f20ae
commit e9de5d5c32
3 changed files with 18 additions and 6 deletions

View File

@ -11,19 +11,15 @@ class NotificationsMailer < ApplicationMailer
end end
def domain_expires_soon 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 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 mail subject: subject, to: @notification.recipient
end end
end end
def ssl_expires_soon 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 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 mail subject: subject, to: @notification.recipient
end end
end end

View File

@ -105,6 +105,10 @@ class Check < ApplicationRecord
end end
end end
def domain_expires_in_days
Integer(domain_expires_at.to_date - Time.now.utc.to_date)
end
private private
def domain_created_at_past def domain_created_at_past

View File

@ -123,4 +123,16 @@ class CheckTest < ActiveSupport::TestCase
check.save! check.save!
assert check.mode? assert check.mode?
end 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 end