diff --git a/app/mailers/notifications_mailer.rb b/app/mailers/notifications_mailer.rb index b57de6c..b20e4a7 100644 --- a/app/mailers/notifications_mailer.rb +++ b/app/mailers/notifications_mailer.rb @@ -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 diff --git a/app/models/check.rb b/app/models/check.rb index 4c744b0..c2c04b5 100644 --- a/app/models/check.rb +++ b/app/models/check.rb @@ -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 diff --git a/test/models/check_test.rb b/test/models/check_test.rb index 22fecc1..000d34e 100644 --- a/test/models/check_test.rb +++ b/test/models/check_test.rb @@ -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